问题
I made an application which shows the current location of the user using the MyLocationOverlay class. However, when the user changes his location, the marker is not recentered. How do I implement the "follow me" feature?
I am thinking of making the LocationManager to update as frequently as possible and then calling the animateTo method inside the onLocationChanged method but it seems to be a bad solution. Is there any way of doing it?
回答1:
What I do is extend MyLocationOverlay
as an inner class of my MapActivity
. Then, I override onLocationChanged
and use animateTo
on my MapController
in that 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);
}
来源:https://stackoverflow.com/questions/8394867/how-do-you-implement-follow-me-using-the-mylocationoverlay-class