To achieve this I feel I simply need to override onMarkerClick
and check if the infoWindow of clicked marker has already been open, but to my surprise clickedMarker.isInfoWindowShown()
always return false...
My codes:
@Override
public boolean onMarkerClick(final Marker clickedMarker) {
if(clickedMarker.isInfoWindowShown()) {
clickedMarker.hideInfoWindow();
System.out.println("was showing");
} else {
clickedMarker.showInfoWindow();
System.out.println("not showing");
}
}
It always tells me the infoWindow is "not showing" which is not right... I can get around this by keeping a reference of userLastClickedMarker
but I'd like to know where I did wrong above.
Thanks!
Edit:
I changed my code to debug this issue:
System.out.println(clickedMarker.isInfoWindowShown());
if(clickedMarker.isInfoWindowShown()) {
clickedMarker.hideInfoWindow();
System.out.println(" showing");
} else {
clickedMarker.showInfoWindow();
System.out.println("not showing");
}
System.out.println(clickedMarker.isInfoWindowShown());
I found that isInfoWindowShown()
does work correctly in onMarkerClick method but won't 'remember' it correctly. And I found this has been pointed out as a bug by someone already...
https://code.google.com/p/gmaps-api-issues/issues/detail?id=5408
After constructing an InfoWindow, you must call open to display it on the map. The user can click the close button on the InfoWindow to remove it from the map, or the developer can call close() for the same effect.
Call setPosition() on the info window, or. Attach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.
You can modify the whole InfoWindow using jquery alone... var popup = new google. maps. InfoWindow({ content:'<p id="hook">Hello World!
isInfoWindowShown always false, so I hide info window using the basic way
int mLastIndex = -1
and on
@Override
public boolean onMarkerClick(Marker marker) {
int index = (int) marker.getTag();
Log.i(TAG, "onMarkerClick: " + index);
if(lastIndex != index){
marker.showInfoWindow();
lastIndex = index;
}else{
marker.hideInfoWindow();
lastIndex = -1;
}
return true;
}
I had the same issue and I found a simple solution by declaring a global boolean variable and switching its value when user clicks on a marker. Here's my code:
private boolean isInfoWindowShown = false;
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (!isInfoWindowShown) {
marker.showInfoWindow();
map.moveCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
isInfoWindowShown = true;
} else {
marker.hideInfoWindow();
isInfoWindowShown = false;
}
return true;
}
});
Hope this will help somebody.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With