Skip to content Skip to sidebar Skip to footer

Clickable Google Maps Marker In Fragment

What I am trying to accomplish here is be able to show a AlertDialog when I click on a marker that is dynamically added on load (call an API, get positions and show them on map). T

Solution 1:

I don't know why but Google Maps API can't used as implement to fragments. Following code may work it for you. You just need to assign markerClickListener for local, not implementing MarkerClickListener.

   //Detect location and set on map
    mMapView.getMapAsync(new OnMapReadyCallback() {
        @SuppressLint("MissingPermission")
        @Override
        public void onMapReady(GoogleMap mMap) {
            googleMap = mMap;
            // Bla
            // Bla
            // Bla your codes about map
            googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {
                    // Triggered when user click any marker on the map
                    return false;
                }
            });
        }
    });

Post a Comment for "Clickable Google Maps Marker In Fragment"