【发布时间】:2013-08-30 14:02:27
【问题描述】:
我有一个 android 应用程序需要确定其当前位置(使用 Google Play 服务 LocationClient),然后将该位置发送回服务器。这需要在后台定期发生,例如每 5 分钟一次
此代码运行良好,它通常每 5 分钟提供一次位置,误差在几秒内。当android无法修复时会出现问题。在这些情况下,我希望回调在 5 分钟后使用 NULL 位置对象运行,但是这不会发生。应用程序只是继续寻找位置而不调用回调。
我调用我的 LocationClient 的 requestLocationUpdates 方法,并使用如下创建的 locationRequest 对象
locationrequest = LocationRequest.create();
locationrequest.setInterval(5 * 60 * 1000);
locationrequest.setFastestInterval(3 * 60 * 1000);
locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationrequest.setExpirationDuration(45 *1000);
locationclient.requestLocationUpdates(locationrequest, mPendingIntent);
我看不到让 LocationClient 每 5 分钟呼叫我一次的合适方法,即使它无法获取位置也是如此。我很感激我可以每 5 分钟发出一次警报,然后将最近的位置发送回服务器,但我希望在回调中处理发送。
有没有其他人必须处理这种情况,或者知道如何解决它?
【问题讨论】:
-
请记住,您使用的是
locationclient.requestLocationUpdates...,您将收到更新通知,但如果设备无法获取位置,它将不会更新,因此不会通知。您可能想通过运行计时器或类似的东西来尝试不同的方法。每个文档:It may take a while to receive the first location update. If an immediate location is required, applications may use the getLastKnownLocation(String) method. -
我的 4.0 手机一直在寻找某个位置时遇到问题,只有当我(手动)关闭使用辅助 gps 时,它才能在可接受的参数范围内运行。
标签: android gps google-play-services location-client