问题
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