How to implement the current update of the user's current location?

I use MyLocationOverlay to display the current location. However, updating the location takes some time. I wanted to implement something like the “follow me” function on the iPhone, where the user's location also moves as the user moves. How to make a MyLocationOverlay marker to perform a real-time update in its place?

Note that I override draw () and drawMyLocation () because I need to draw a custom marker.

My current code is as follows: (The problem with my code is that the token does not move with the user. Since it takes some time before calling onLocationChanged, the token will just suddenly jump from one place to another.)

@Override public synchronized void onLocationChanged(Location location) { if (location != null && mapController != null) { //Recenter map based on current location mapController.animateTo(new GeoPoint((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6))); } super.onLocationChanged(location); } 
+4
source share
1 answer

You can give a minimum interval between the location manager and the wait time between calls to this method, but it doesn’t quite remind that the interval is 100% of the time (see the description of LocationManager.requestLocationUpdates () ). Maybe shorter, maybe more - because, for example, it can be cloudy and the GPS chip will not be able to receive location updates as regularly as you would like.

There is no right way to overcome this - location services will always have flaws. Each location-oriented application used to “freeze” with a marker from time to time because the gps chip lost the fix for a moment.

The only thing you can do to smooth it a bit is to remember the speed of the movement, and if gps loses its correction, give fake marker map updates based on the assumption that the user is moving in the same direction at the same speed as they were, when gps had a fix. But this only makes sense so that 2-5 will skip real updates (just to smooth out cases where the fix is ​​lost within a few seconds).

UPD To do this, you can implement a view of the proxy server location listener, which will update your token, strictly observing the intervals you specify, for example. every 200 ms and do it based on the saved location. And the stored location can be asynchronously updated by the real location receiver. Location objects have a correction time that provided the data (see the getTime () method ), you can use this to determine if you should “predict” the next marker movement or location is old enough to refuse and notify the user that that gps doesn't know where they are :)

+2
source

Source: https://habr.com/ru/post/1395244/


All Articles