Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 692
MineConsulting SRL Avatar asked Dec 31 '12 12:12

MineConsulting SRL


Video Answer


2 Answers

Change the return statement

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

      (to)

 @Override
public boolean onMarkerClick(Marker marker) {
return true;
}
like image 189
Satheesh Avatar answered Oct 29 '22 20:10

Satheesh


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;
        }
    }
}
like image 36
Edwin Avatar answered Oct 29 '22 20:10

Edwin