Always show map marker title in Android
There are two methods for showing and hiding the markers. The boolean return value simply prevents the default behaviour from taking place (false) or allows it to happen (true). In other words, it informs the system whether you consumed the event or not. See Google API Reference.
private GoogleMap.OnMarkerClickListener onMarkerClickedListener = new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (marker.isInfoWindowShown()) {
marker.hideInfoWindow();
} else {
marker.showInfoWindow();
}
return true;
}
};
mGoogleMap.setOnMarkerClickListener(onMarkerClickedListener);
It is very easy:
locationMarker.showInfoWindow();
Just return false for onMarkerClickListener
, if you return true shows the infoWindow
.
To hide title when we click on marker:
map.setOnMarkerClickListener(this);
...
@Override
public boolean onMarkerClick(Marker arg0) {
Log.i(TAG,"marker arg0 = "+arg0);
return false;
}
If we return true title will be display, else if we return false title won't display.
use showInfoWindow()
and add marker as below.
Marker marker = mMap.addMarker(new MarkerOptions().position(currentPosition).title("Your text"));
marker.showInfoWindow();