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

半城伤御伤魂 提交于 2019-12-11 00:54:22

问题


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

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