android-maps-utils
android-maps-utils copied to clipboard
setOnMarkerClickListener not working
Summary
I need your help because i'm going crazy with the setOnMarkerClickListener. I am using the MarkerManager.Collection but onMarkerClick is never triggered.
Observed behavior
When I click on a marker the camera centers on it but i can find a way to override the behavior. I tried to to set the listener with the google map object and with the MarkerManager.Collection but nothing seems to work.
Environment details
The library versions are :
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'com.google.maps.android:android-maps-utils:2.3.0'
Code example
SupportMapFragment map = SupportMapFragment.newInstance();
ActivityUtils.addFragmentToActivity(getChildFragmentManager(), map, R.id.container_map_walk_details, FRAGMENT_MAP_TAG);
map.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
MarkerManager markerManager = new MarkerManager(googleMap);
MarkerManager.Collection collection = markerManager.newCollection();
collection.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker) {
// never triggerred....
}
});
.
.
Marker marker = collection.addMarker(markerOptions);
}
});
Please what am I missing ??
Thanks!
can you please share a runnable code snippet ?
I have the same problem, my guess is that adding @SuppressLint("PotentialBehaviorOverride") to the method you pass as setOnMarkerClickListener or to the method where you initialize collection's listener should solve it, but i didnt try it myself yet
@SuppressLint() commands are just Lint commands. They do not affect the runtime of the code,hence u wont see any difference on the running application.
Please share a buildable/runnable source code so i can reproduce it
PS i am using click listeners on marker collections,in my released app and works fine
Hey @WilliamMouline ,
The click listeners seem to be working, maybe there is something specific in your code.
I am closing this ticket. Feel free to reopen it and provide a code snippet that we can analyze.
Thanks.