Reputation: 55
I am creating an app which can show the navigation path between two points in the google maps API in Android. When user clicks on the map somewhere, a marker is added at that place. When user clicks 2nd time, another marker is added and optimized navigation path is shown to the user in my application.
There is a JSON file provided by https://maps.googleapis.com/maps/api/directions/ which contains address of origin and destination. I have parsed that JSON file and stored the addresses.
Now the problem is, I have added the origin and destination markers already to the map by clicking on the map. and I want to provide title (address) to both the markers. But I guess we can not change the details after we have added the markers in the map.
Please reply. Thanks in advance.
Upvotes: 2
Views: 2071
Reputation: 415
marker = mMap.addMarker(new MarkerOptions()
.position(latLng)
.title("Perth")
.flat(true));
.snippet("Population: 1,738,800"));
.title for setting tittle and .snippet for little details under title aand this code to method addMarkersToMap()
and if you click on marker it'll appear and disppear
Upvotes: -1
Reputation: 243
You need to keep Marker after adding MarkerOptions to the map. Let me show you an example of what should be done:
GoogleMap map = ... // get a map.
// Add a marker at San Francisco.
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183))
.title("San Francisco")
.snippet("Population: 776733"));
marker.setTitle("MY MARKER'S NEW TITLE")
Sources: https://developers.google.com/android/reference/com/google/android/gms/maps/model/Marker?hl=pt-br
Changing a Marker's text in Android GoogleMaps
Upvotes: 1
Reputation: 863
You can change marker tile by marker.setTitle("title")
method and then refresh the marker-view by following
marker.hideInfoWindow();
marker.showInfoWindow();
Upvotes: 1