【发布时间】:2013-04-04 21:03:37
【问题描述】:
我的应用正在使用 requestLocationUpdates(来自 GPS 和网络,以先到者为准)。
我的代码:
LocationManager lm = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
myLocationListenerInstance);
timeout = new Timer();
timeout.schedule(myGetLastKnownLocationInstance, TIMEOUT);
myGetLastKnownLocationInstance 正在使用 getLastKnownLocation。
我的问题:
从当前正在运行的 Activity 调用此代码时,myLocationListenerInstance 会在不到 TIMEOUT 秒内收到通知。
但是,当从后台服务调用时,我会超时,并且输出是通过最后一个已知位置。最糟糕的是,在调查测量的Location时,时间戳小于TIMEOUT!
即使将 TIMEOUT 设置为一分钟,我也会遇到这种情况。
有什么建议吗?谢谢
【问题讨论】:
标签: android location android-service locationmanager android-context