How do you implement “follow me” using the MyLocationOverlay class?

I made an application that shows the user's current location using the MyLocationOverlay class. However, when the user changes his location, the marker does not return. How to implement the function "follow me"?

I am thinking about updating the LocationManager as often as possible, and then calling the animateTo method inside the onLocationChanged method, but it seems like a bad solution. Is there any way to do this?

+2
source share
1 answer

I am doing the MyLocationOverlay extension as an inner class of my MapActivity . Then I override onLocationChanged and use animateTo in my MapController in this method.

 @Override public synchronized void onLocationChanged(Location location) { if (location != null) { mapController.animateTo( new GeoPoint((int) (location.getLatitude()*1e6), (int) (location.getLongitude()*1e6)); } super.onLocationChanged(location); } 
+2
source

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


All Articles