在我的应用程序中,我已经在地图上有一些静态覆盖图,并且一个动态改变了它在GPS坐标改变时的位置。OSMDroid覆盖多个静态和一个动态
我的问题是,当GPS COORDS改变,我需要清除动态覆盖,并创建一个新的,但是当我这样做,它会清除所有覆盖,使用:
mapView.getOverlays().clear();
所以,我试图找到更好的方式来做到这一点。
清除所有覆盖图,然后再将它们放在地图上(消耗内存),或者我可以清除特定覆盖图吗?
感谢
编辑:
这是动态标记:
@Override
public void onLocationChanged(Location location) {
Log.d("Location", "onLocationChanged with location " + location.toString());
mLatitude = (int) (location.getLatitude() * 1E6);
mLongitude = (int) (location.getLongitude() * 1E6);
GeoPoint gpt = new GeoPoint(mLatitude,mLongitude);
markerYou.clear();
markerYou.add(new OverlayItem(getString(R.string.markerYou), getString(R.string.markerYouDescription), gpt));
mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(markerYou, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
@Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
Toast.makeText(ShowMap.this, getString(R.string.markerYouDescription), Toast.LENGTH_SHORT).show();
return true;
}
@Override
public boolean onItemLongPress(final int index, final OverlayItem item) {
Toast.makeText(ShowMap.this, getString(R.string.markerYouDescription),Toast.LENGTH_SHORT).show();
return true;
}
}, mResourceProxy);
mapView.getOverlays().clear();
mapView.getOverlays().add(mMyLocationOverlay);
mapView.invalidate();
mapController.setCenter(gpt);
}
这是放置静态标记功能:
public void putPlacesOfInterest(){
this.dh = new DataHelper(ShowMap.this);
List<Pontos> list = this.dh.selectAll();
for(Pontos p : list){
markerPlaces.add(new OverlayItem(p.getName().toString(), p.getName().toString(), new GeoPoint(p.getLat(), p.getLng())));
}
mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(markerPlaces, new OnItemGestureListener<OverlayItem>() {
@Override
public boolean onItemLongPress(int index, OverlayItem item) {
Toast.makeText(ShowMap.this, "Item " + item.mTitle, Toast.LENGTH_LONG).show();
return true;
}
@Override
public boolean onItemSingleTapUp(int index, OverlayItem item) {
Toast.makeText(ShowMap.this, "Item " + item.mTitle, Toast.LENGTH_LONG).show();
return true;
}
}, mResourceProxy);
mapView.getOverlays().add(mMyLocationOverlay);
mapView.invalidate();
}
标记的声明是什么样的? – 2013-08-27 17:08:29