Skip to content

Instantly share code, notes, and snippets.

@ronanguilloux
Created February 9, 2012 15:56
Show Gist options
  • Select an option

  • Save ronanguilloux/1780787 to your computer and use it in GitHub Desktop.

Select an option

Save ronanguilloux/1780787 to your computer and use it in GitHub Desktop.
Google Map markers : Same positions, disambiguation needed
// source : http://techxplorer.com/2010/02/05/managing-markers-with-the-same-coordinates-in-a-google-map/
// get the coordinates
var hash = points[i].getAttribute("lat") + points[i].getAttribute("lng");
hash = hash.replace(".","").replace(",", "").replace("-","");
// source : http://techxplorer.com/2010/02/05/managing-markers-with-the-same-coordinates-in-a-google-map/
// check to see if we've seen this hash before
if(coords[hash] == null) {
// get coordinate object
var latlng = new google.maps.LatLng(parseFloat(points[i].getAttribute("lat")), parseFloat(points[i].getAttribute("lng")));
// store an indicator that we've seen this point before
coords[hash] = 1;
} else {
// add some randomness to this point
var lat = parseFloat(points[i].getAttribute("lat")) + (Math.random() -.5) / 1500;
var lng = parseFloat(points[i].getAttribute("lng")) + (Math.random() -.5) / 1500;
// get the coordinate object
var latlng = new google.maps.LatLng(lat.toFixed(6), lng.toFixed(6));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment