Updating a map marker in android

2020-08-26 08:46发布

问题:

Using Google Maps Android API v2, I can update my marker's position by getting the Marker from a hashMap and then calling:

Marker marker = hashMap.get(someId);
marker.setTitle("Title");
marker.setSnippet("Snippet");
marker.setPosition(new LatLng(newLatitude, newLongitude));

However, if the marker is selected when this is called, the title and snippet will only update if I click off the marker and reselect it. Is there anyway to tell the map to refresh the data in the marker bubble?

回答1:

Call hideInfoWindow() immediately followed by a call to showInfoWindow(), like this:

marker.hideInfoWindow();
marker.showInfoWindow();