In my application, I already have some static overlays on the map, and one dynamic which changes it's place when GPS coords change.
My problem is that, when the GPS coords change, I have to clear the dynamic overlay and create a new one, but when I do that, it clears all the overlays, using:
mapView.getOverlays().clear();
So, I'm trying to find the better way to do it.
Clear all the overlays and then place them again on the map (memory consuming) or can I clear a specific overlay?
Thanks
Edit:
This is the dynamic marker:
@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);
}
This is the function that places the static markers:
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();
}