Skip to content

Instantly share code, notes, and snippets.

@avioing
Created March 16, 2011 19:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avioing/873142 to your computer and use it in GitHub Desktop.
Save avioing/873142 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link
Author

avioing commented Nov 15, 2011

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

@DimitarBrankov
Copy link

Great solution!
Thanks!

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