googlemaps/android-maps-utils

After adding geoJson layer on map marker click listener not working..

Yousaf128 opened this issue · 2 comments

After adding geoJson layer on map marker click event not triggered. Below is the code Snippet.

Here is the code for add Markers on Map:

 val markerManager = MarkerManager(mMap)
        val markerCollection: MarkerManager.Collection = markerManager.newCollection()
        
  markerCollection.addMarker(
                MarkerOptions().position(latLng)
                    .icon(BitmapDescriptorFactory.fromBitmap(iconGenerator.makeIcon()))
                    .title("marker title")
            )
            
            markerCollection.setOnMarkerClickListener { marker: Marker ->
           Toast.makeText(this, "Done", Toast.LENGTH_SHORT).show()
            false
        }

Here is the code for add geoJson layer on Google map:

   val markerManager = MarkerManager(mMap)
                   val groundOverlayManager = GroundOverlayManager(mMap)
                   val polygonManager = PolygonManager(mMap)
                   val polylineManager = PolylineManager(mMap)

                   geoJsonLayer = GeoJsonLayer(
                       mMap,
                       geoJson,
                       markerManager,
                       polygonManager,
                       polylineManager,
                       groundOverlayManager
                   )

                   geoJsonLayer!!.addLayerToMap()

                   geoJsonLayer!!.features.forEach { it ->
                       it.lineStringStyle = GeoJsonLineStringStyle().apply {
                           this.isClickable = true
                           color = Color.BLUE
                       }
                   }

After adding layer marker click event not working. how to fix ? .Thanks

You have added a GeoJsonLayer, and by default this will be handling the clicks.

Your code seems correct, but you need to pass the same MarkerManager you are using to add the Markers to the GeoJsonLayer. In the code provided, it seems that you are creating a new one.

Can you try reusing the same MarkerManager for the GeoJsonLayer? Let me know if that works.

I am closing this @Yousaf128 , let me know if you have any issues after applying the suggested fix above.