具有模拟位置提供程序的 Android 地理围栏

标签 android android-location android-geofence

我已经开始在 Android 上开发最后一个位置服务功能:Geofences!模拟位置提供程序是否存在任何已知问题?以下示例(https://developer.android.com/training/location/geofencing.html)即使当前位置在地理围栏内,我的 Intent 服务也从未触发。我正在使用 FakeGPS android 应用程序作为模拟位置提供程序,如果我模拟一条路线,我会在 Google map 应用程序上看到位置变化,因此模拟位置提供程序运行良好。有什么想法吗?

谢谢。 保罗。

最佳答案

我一直在努力让它发挥作用。多么痛苦的谷歌!因为它说可以使用模拟轻松地测试地理围栏。

魔术是在传递给 setMockLocation 的 Location 中使用提供者名称“network”。

    Location location = new Location("network");
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    location.setTime(new Date().getTime());
    location.setAccuracy(3.0f);
    location.setElapsedRealtimeNanos(System.nanoTime());

    LocationServices.FusedLocationApi.setMockLocation(_googleApiClient, location);

关于具有模拟位置提供程序的 Android 地理围栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17048972/

相关文章:

android - 我的应用无法访问特定设备的位置

android - LocationManager初始化后为null

android - "GeofencingAPI is deprecated"

android - 使用地理围栏时如何从 BroadcastReceiver 通知调用 Activity

android - 如何在屏幕中央的所有小部件顶部显示 CircularProgressIndicator

android - 在 android 中流式传输 url

android - SavedInstanceState 在 fragment 中始终为空

安卓 : Horizontal slide activity (such as Play Store)

java - Android Google Play 位置服务在离开应用程序后继续

java - 尝试使用地理围栏和php在android中实现考勤