I use Google Maps in an app and it is likely that multiple markers are attached to same location where each marker represent a person. In this situation user will not know t
Inspired by the Geek's answer, I created a function. This function returns a new latitude longitude pair, nearby the original value, almost in a circular fashion. COORINDATE_OFFSET is adjustable based on the need.
private static final float COORDINATE_OFFSET = 0.000085f;
private ArrayList markerCoordinates = new ArrayList<>();
private int offsetType = 0;
private LatLng getLatLng(LatLng latLng) {
LatLng updatedLatLng;
if (markerCoordinates.contains(latLng)) {
double latitude = 0;
double longitude = 0;
if (offsetType == 0) {
latitude = latLng.latitude + COORDINATE_OFFSET;
longitude = latLng.longitude;
} else if (offsetType == 1) {
latitude = latLng.latitude - COORDINATE_OFFSET;
longitude = latLng.longitude;
} else if (offsetType == 2) {
latitude = latLng.latitude;
longitude = latLng.longitude + COORDINATE_OFFSET;
} else if (offsetType == 3) {
latitude = latLng.latitude;
longitude = latLng.longitude - COORDINATE_OFFSET;
} else if (offsetType == 4) {
latitude = latLng.latitude + COORDINATE_OFFSET;
longitude = latLng.longitude + COORDINATE_OFFSET;
}
offsetType++;
if (offsetType == 5) {
offsetType = 0;
}
updatedLatLng = getLatLng(new LatLng(latitude, longitude));
} else {
markerCoordinates.add(latLng);
updatedLatLng = latLng;
}
return updatedLatLng;
}