This uses the Haversine formula to calculate the great-circle distance between two points.
distanceLatLng (
latitude1, longitude1, // first coordinates
latitude2, longitude2, // seconds coordinates
diameter // earth diameter (might be any unit)
)
// returns the distance in the specified unit
- 2 * 6378.137 Kilometers
- 2 * 6378137 Meters
- 2 * 3963.190 Miles
Created by Martin Kleppe (@aemkei) at Ubilabs.
Check his "JavaScript Golf Lessons" slides.
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.