Codename one retrieving location at regular time intervals

北城以北 提交于 2019-12-23 02:49:09

问题


I am trying to get location coordinates using code name one using the following code loc = LocationManager.getLocationManager().getCurrentLocation();

I am invoking the above method to run at regular intervals by calling it inside a UITimer. The problem is I am not able to get the accurate location using the above code. Even though this method is called for every 10 seconds I see change in coordinates only at 4-5 minutes interval. I am testing by carrying the device in vehicle which is moving constantly. I have tried using getCurrentLocationSync() but no luck. Any suggestions on improving the location accuracy?


回答1:


You must never do location polling as it will kill the battery and doesn't work properly on devices. If you want to get location updates on a running application just use location listener with setLocationListener.

It will get invoked as you move around.

If you want to get location events in the background when your app is minimized then you will need the background location support (geofencing).



来源:https://stackoverflow.com/questions/35118474/codename-one-retrieving-location-at-regular-time-intervals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!