android-maps-utils icon indicating copy to clipboard operation
android-maps-utils copied to clipboard

setOnMarkerClickListener not working

Open WilliamMouline opened this issue 2 years ago • 3 comments

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!

WilliamMouline avatar May 11 '22 14:05 WilliamMouline

can you please share a runnable code snippet ?

dkati avatar Jun 29 '22 08:06 dkati

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

MadRatSRP avatar Sep 11 '22 11:09 MadRatSRP

@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

dkati avatar Sep 12 '22 05:09 dkati

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.

kikoso avatar Dec 05 '22 07:12 kikoso