i have two marker in example where one is for current location and one is for destination i have drawn a Route path between them but now in same example i want to set a click listener on both the marker can you suggest some good example related this ..?
Here is how to do it using Kotlin:
private lateinit var mMap: GoogleMap //declaration inside class
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
mMap.setOnMarkerClickListener { marker ->
if (marker.isInfoWindowShown) {
marker.hideInfoWindow()
} else {
marker.showInfoWindow()
}
true
}
}
Hope this helps some beginner like me.
This is how you would go about adding an onClick
listener for markers on a map:
GoogleMap mMap;
Marker marker = mMap.addMarker(
new MarkerOptions()
.position(new LatLng(dLat, dLong))
.title("Your title")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker m) {}
}
OnMarkerClickListener
googleMap.setOnMarkerClickListener(this);
in your setupOverride the onMarkerClick
@Override
public boolean onMarkerClick(final Marker marker) {
//handle click here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With