MineConsulting SRL
MineConsulting SRL

Reputation: 2340

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.

Upvotes: 13

Views: 12992

Answers (4)

Mina N. H. Ibrahim
Mina N. H. Ibrahim

Reputation: 11

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.

Upvotes: 0

Satheesh
Satheesh

Reputation: 1730

Change the return statement

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

      (to)

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

Upvotes: 16

Delari Jesus
Delari Jesus

Reputation: 411

Use

    mapa.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

            @Override
            public void onInfoWindowClick(Marker marker) {


                marker.hideInfoWindow();
            }
        });

I hope that helps.

Upvotes: 11

Edwin
Edwin

Reputation: 61

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

Upvotes: 6

Related Questions