I want to add a marker click event for both clustered markers and unclustered markers. The clustered markers are working by passing the cluster manager into the marker click event. However, by doing that it overrides the marker click event for the unclustered markers and vice versa. I have images for the clustered markers and regular map pin markers for the non-clustered markers.
I want to be able to remove the unclustered markers on marker click. I have tried a map long click event given a distance such as:
@Override
public void onMapLongClick(LatLng latLng) {
for (Marker marker : listOfGeoTagMarkers) {
/* if(Math.abs(marker.getPosition().latitude - latLng.latitude) < 0.05 && Math.abs(marker.getPosition().longitude - latLng.longitude) < 0.05) {
Toast.makeText(MapActivity.this, "got clicked", Toast.LENGTH_SHORT).show(); //do some stuff
break;
}*/
double distance = SphericalUtil.computeDistanceBetween(
marker.getPosition(), latLng);
if ( distance < 300 ) { // closer than 50 meters?
Toast.makeText(MapsActivity.this, "got clicked", Toast.LENGTH_SHORT).show();
}
}
However, the distance multiplier (here it is 300 but it could be 50 or 100 etc.) Is too indecisive at certain zoom levels with the pins. Distance is fine if you are zoomed all the way in and can accurately touch around the marker.
However, when you zoomed out the distance infeasible increases or decreases too dramatically to accurately do what is needed. The simple toast event is where I would put the delete code for the marker in question.
Any help is appreciated.