Search code examples
androidgoogle-mapsitemizedoverlay

Android: changing the location of an overlay


How do i go about changing the location of an overlay. Now, one way is to remove the original overlay n draw a new one. Doing this changes the index of all overlays drawn after it.

For my application, each overlay represent a user with a certain ID. when this user moves, i need to update his location. If i remove the overlay from the list, them the hashmap i am using to locate the overlay for this user, will be rendered useless.

How should I go about doing this?


Solution

  • There is no way that I know of. You can simply

         // remove the old key association 
         hMap.remove(idForOverlay);
         // add a new one
         hMap.put(idForOverlay, newOverlayItem);
         // add item to the overlays
         mapView.getOverlays().add(newOverlayItem);
         mapView.invalidate();
    

    Actually you don't even have to remove() and put() will replace the current association with the newly added association with the key. The current association is returned as an Object