Changing a Marker's text in Android GoogleMaps

假装没事ソ 提交于 2019-12-10 20:36:26

问题


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.


回答1:


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.




回答2:


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)));
    }
}


来源:https://stackoverflow.com/questions/19009863/changing-a-markers-text-in-android-googlemaps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!