Create a gist now

Instantly share code, notes, and snippets.

adjusting coordinates of markers with identical coordinates
// add this inside your loop - looping over your marker locations
var coordinates_hash = new Array();
var coordinates_str, actual_lat, actual_lon, adjusted_lat, adjusted_lon;
actual_lat = adjusted_lat = this.locations[i].latitude;
actual_lon = adjusted_lon = this.locations[i].longitude;
coordinates_str = actual_lat + actual_lon;
while (coordinates_hash[coordinates_str] != null) {
// adjust coord by 50m or so
adjusted_lat = parseFloat(actual_lat) + (Math.random() -.5) / 750;
adjusted_lon = parseFloat(actual_lon) + (Math.random() -.5) / 750;
coordinates_str = String(adjusted_lat) + String(adjusted_lon);
}
coordinates_hash[coordinates_str] = 1;
var myLatLng = new google.maps.LatLng(adjusted_lat, adjusted_lon);
@otar
otar commented Nov 15, 2011

Simply a "life-saver"...

Though have to be honest that I appeared dumb enough not to Goggle possible solution(s) and code it from scratch.

@avioing
Owner
avioing commented Nov 15, 2011

glad it's helpful. check out the gmaps4rails gem, it has this feature built-in along with many others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment