我已经开始在 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/