Android Mapview Can't Remove Marker
Solution 1:
according to Dave's suggestion this fixed the problem :
publicvoidonLocationChanged(Location location) {
if(mMyOverlay == null) {
mMyOverlay = new myOverlay(getResources().getDrawable(R.drawable.arrow),MyMap);
MyMap.getOverlays().add(mMyOverlay);
}else{
MyMap.getOverlays().remove(mMyOverlay);
MyMap.invalidate();
mMyOverlay = new myOverlay(getResources().getDrawable(R.drawable.arrow),MyMap);
MyMap.getOverlays().add(mMyOverlay);
}
if(location!=null){
MyMap.invalidate();
GeoPoint MyPos = new GeoPoint(microdegrees(location.getLatitude()),microdegrees(location.getLongitude()));
MyController.animateTo(MyPos);
mMyOverlay.addPoint(MyPos,"Ma position","Ma position");
}
thanks..
Solution 2:
getOverlays()
returns the List of Overlay objects in your MapView. Each time the location is updated, your code is adding another overlay to this list. You need to do is remove the previous overlay, or empty the list entirely each time.
So, in your method call getOverlays().clear()
before adding your new overlay.
Edit, alternatively maybe this will point you in the right direction? I don't know exactly how your myOverlay class works, so hopefully you can fill in the blanks!
protected myOverlay mMyOverlay;
publicvoidonLocationChanged(Location location) {
if(mMyOverlay == null) {
mMyOverlay = new myOverlay(getResources().getDrawable(R.drawable.arrow),MyMap);
MyMap.getOverlays().add(mMyOverlay);
if(location!=null){
MyMap.invalidate();
GeoPoint MyPos = new GeoPoint(microdegrees(location.getLatitude()),microdegrees(location.getLongitude()));
MyController.animateTo(MyPos);
mMyOverlays.setPoint(MyPos,"Ma position","Ma position");
}
}
Solution 3:
Use an ItemizedOverlay, and as Dave suggested, keep track of the one you want moved and then either delete the tracked OverlayItem and add a new one or take the tracked one, get its marker or MapPoint and reset its lat/lon coordinates to the new location coordinates. You may also have to call mapView.invalidate() to force a redraw.
Post a Comment for "Android Mapview Can't Remove Marker"