简体   繁体   中英

Hide infowindow android map api v2

I was trying to close the default infowindow in the android map. I used .hideInfoWindow() but nothing appends. Thanks.

Change the return statement

 @Override
public boolean onMarkerClick(Marker marker) {
return false;
}

      (to)

 @Override
public boolean onMarkerClick(Marker marker) {
return true;
}

Use

    mapa.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

            @Override
            public void onInfoWindowClick(Marker marker) {


                marker.hideInfoWindow();
            }
        });

I hope that helps.

I assume you want to close the infowindow when you click the marker for the second time. It seems you need to keep track of the last clicked marker. I can't get it to work by simply checking if the clicked marker is currently shown and then close it, but this works nicely.

private Marker lastClicked;

private class MyMarkerClickListener implements OnMarkerClickListener {

    @Override
    public boolean onMarkerClick(Marker marker) {
        if (lastClicked != null && lastClicked.equals(marker)) {
            lastClicked = null;
            marker.hideInfoWindow();
            return true;
        } else {
            lastClicked = marker;
            return false;
        }
    }
}

Setting the pin title and snippet to null, will result in no info window being displayed. This shall cover both cases when selecting and clicking a pin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM