Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android App Map center when touchs a marker

When I touch a marker on map fragment (v.2), the map is centralized on the touched marker position. How can I drop this behavior? Is it possible? I'd like to keep the title being presented, but with no centralization.

Thanks a lot,

Julio

like image 207
user2131917 Avatar asked Dec 29 '25 18:12

user2131917


1 Answers

From the documentation:

You can use an OnMarkerClickListener to listen for click events on the marker. To set this listener on the map, call GoogleMap.setOnMarkerClickListener(OnMarkerClickListener). When a user clicks on a marker, onMarkerClick(Marker) will be called and the marker will be passed through as an argument. This method returns a boolean that indicates whether you have consumed the event (i.e., you want to suppress the default behavior). If it returns false, then the default behavior will occur in addition to your custom behavior. The default behavior for a marker click event is to show its info window (if available) and move the camera such that the marker is centered on the map.

This way, you can override the default behavior (center mark+show infowindow) with your custom behavior (show infowindow). Something like this should work:

On your OnMarkerClickListener:

public boolean onMarkerClick(Marker marker) {
    marker.showInfoWindow();
    return true;
}
like image 92
Marcelo Avatar answered Jan 01 '26 06:01

Marcelo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!