Google Maps hide marker marker in Android

I am trying to add a marker to my google map. Here is the code.

private final LatLng LOCATION_HOME= new LatLng(6.0334009,80.218384);


 mMap.addMarker(new MarkerOptions()
                    .position(LOCATION_HOME)
                    .title("Hi I'm Home..:D")
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE))
    );

Using this code, I can get the marker title by touching the marker. How to hide marker title by touching it again?

I tried to find a method. But, glasses only say how to hide markers. but I need the marker to stay and hide only the name of the marker.

Thanks in advance.

+4
source share
3 answers

You can use this callback to control a click on the info window.

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {

        }
    });

Or maybe you better implement this method:

public boolean onMarkerClick(Marker marker)

Then you can call

hideInfoWindow()

on the marker to hide it.

Hope this helps.

+4
source

First create a marker variable

Marker mMarker = mMap.addMarker(markerOptions);

,

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
    @Override
    public boolean onMarkerClick(Marker marker) {
        if (marker.equals(mMarker))
            marker.hideInfoWindow();
        return true;
    }
});

mMap.setOnInfoWindowClickListener(),

+1

Create a marker object and call marker.hideInfoWindow (); look it up

Marker marker = googleMap.addMarker(new MarkerOptions()

marker.hideInfoWindow ();

0
source

Source: https://habr.com/ru/post/1610538/


All Articles