Created
March 16, 2011 19:26
-
-
Save avioing/873142 to your computer and use it in GitHub Desktop.
adjusting coordinates of markers with identical coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great solution!
Thanks!