在我的應用程序中,我已經在地圖上有一些靜態覆蓋圖,並且一個動態改變了它在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