public
Last active

adjusting coordinates of markers with identical coordinates

  • Download Gist
adjust coordinates
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 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);

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.

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.