如何实现"跟着我"使用MyLocationOverlay类? [英] How do you implement "follow me" using the MyLocationOverlay class?
问题描述
我提出的应用程序,它显示了使用MyLocationOverlay类的用户的当前位置。然而,当用户改变他的位置时,标记不recentered。我如何贯彻落实跟我学功能?
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?
我想制作的LocationManager以尽可能频繁地更新,然后调用onLocationChanged方法里面animateTo方法,但它似乎是一个不好解决。是否有这样做的方法吗?
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?
推荐答案
我做的是延长 MyLocationOverlay
作为一个内部类的我的 MapActivity
。然后,我重写 onLocationChanged
,并使用 animateTo
我的 MapController
在该方法
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);
}
这篇关于如何实现"跟着我"使用MyLocationOverlay类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!