Changing a Marker's text in Android GoogleMaps

2019-07-06 22:51发布

Is it possible to change the text inside a GoogleMap Marker after it's already been set? I'm using MarkerOptions to set the title and snippet originally like this:

SupportMapFragment theMapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap theMap = theMapFragment.getMap();
MarkerOptions theMarker = new MarkerOptions();
theMarker.position(theLatLng);
theMarker.title("My title");
theMarker.snippet("This is my snippet");
theMarker.visible(true);
theMap.addMarker(theMarker);

Later, when the user taps on something, I'd like to perform the reverse geocode lookup and change the title/snippet to contain address information.

2条回答
闹够了就滚
2楼-- · 2019-07-06 23:29

Try this:

  @Override
public boolean onMarkerClick(final Marker marker) {

    if (marker.equals(myMarker)) 
    {
         googleMap.addMarker(new MarkerOptions()
                .position(marker.getPosition())
                .title("Onother title")
                .snippet("snippet")
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    }
}
查看更多
霸刀☆藐视天下
3楼-- · 2019-07-06 23:30

Is it possible to change the text inside a GoogleMap Marker after it's already been set?

Marker has setTitle() and setSnippet() methods. You will need a Marker object representing this marker, probably one that you held onto from the addMarker() call.

查看更多
登录 后发表回答