I've got a map with plenty of large custom markers on it. Now I want to allow the user to create a path on the map (displayed as polyline and later saved as a list of geocoordinate pairs).
If the user clicks on the map I can collect these positions with the setOnMapClickedListener method of the map. But if the user clicks on a marker (setOnMarkerClickedListener), I can only retrieve the markers position (generally the position of the ancor of the marker).
Is it possible to somehow retrieve the clicked map location when actually a marker was clicked?
I'm using the SupportMapFragment.
I think this is a bit late. But i hope this may help you.
mGoogleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
Toast.makeText(
YourActivity.this,
"Lat : " + latLng.latitude + " , "
+ "Long : " + latLng.longitude,
Toast.LENGTH_LONG).show();
}
});
mGoogleMap.setOnInfoWindowClickListener(RegActivity.this);
}
Try like below
mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
LatLng position = marker.getPosition();
Toast.makeText(
MainActivity.this,
"Lat " + position.latitude + " "
+ "Long " + position.longitude,
Toast.LENGTH_LONG).show();
return true;
}
});
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