ait*_*tee 2 android location overlay map
我有一个自定义叠加层,当用户(播放器)移动时,它应该移动.但是我现在拥有它的方式只是不断添加越来越多的叠加层,使得图标具有拖尾效果.
我尝试删除每个位置更新上的叠加层,但它似乎没有删除它.虽然,我不确定是否真正删除它是完成我正在尝试做的正确方法.有没有办法只更新位置和刷新地图?
public void drawMeOnMap()
{
MapView mapView = (MapView) findViewById(R.id.mapView);
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.p18);
itemizedOverlay = new IOverlay(drawable);
if (mapOverlays.contains(itemizedOverlay))
{
mapOverlays.remove(itemizedOverlay);
}
GeoPoint point = new GeoPoint((int)(1E6*player.latitude), (int)(1E6*player.longitude));
OverlayItem item = new OverlayItem(point, "", "");
itemizedOverlay.addOverlay(item);
mapOverlays.add(itemizedOverlay);
}
Run Code Online (Sandbox Code Playgroud)
任何指导将不胜感激.
Rob*_*ond 14
你为什么不只使用MyLocationOverlay?它会为你完成这一切.只需确保调用disableMyLocation()onPause.
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.enableMyLocation();
Run Code Online (Sandbox Code Playgroud)
在任何情况下,您都不需要每次都获得Mapview,mapOverlays,drawable和创建新的itemizedOverlay.这应该只在你的onCreate或其他任何一次.你应该做的只是在位置改变时更新OverlayItem,然后调用mapView.invalidate()来重绘视图.
GeoPoint point = new GeoPoint((int)(1E6*player.latitude), (int)(1E6*player.longitude));
OverlayItem item = new OverlayItem(point, "", "");
itemizedOverlay.clear();
itemizedOverlay.addOVerlay(item);
mapView.invalidate();
Run Code Online (Sandbox Code Playgroud)