Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a map marker in android

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?

like image 539
ingh.am Avatar asked Mar 06 '13 14:03

ingh.am


People also ask

How do I change the marker on Google Maps Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

How do you refresh a marker on Google Maps?

To reload the markers, when you create then, push them to an array. Then create a function where you iterate through the array, setting the markers map as null. After this, erase the array.

How do I make a custom marker map?

Create Custom Maps using Google MapsClick on the “Your Places” option in the menu. Click on the “Maps” Tab in the top right. Click on the “CREATE MAP” link at the bottom of the menu. Once you are on the map creation page, click the marker icon to add a marker to the page.


1 Answers

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

marker.hideInfoWindow();
marker.showInfoWindow();
like image 80
user2334160 Avatar answered Oct 01 '22 23:10

user2334160