Created
April 26, 2014 09:40
-
-
Save poltib/11315885 to your computer and use it in GitHub Desktop.
gmap_script_distance
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
google.maps.LatLng.prototype.kmTo = function(a) { | |
var b, c, d, e, f, g, ra; | |
e = Math; | |
ra = e.PI / 180; | |
b = this.lat() * ra; | |
c = a.lat() * ra; | |
d = b - c; | |
g = this.lng() * ra - a.lng() * ra; | |
f = 2 * e.asin(e.sqrt(e.pow(e.sin(d / 2), 2) + e.cos(b) * e.cos(c) * e.pow(e.sin(g / 2), 2))); | |
return f * 6378.137; | |
}; | |
google.maps.Polyline.prototype.inKm = function(n) { | |
var a, i, len, pathLenght; | |
a = this.getPath(n); | |
len = a.getLength() - 1; | |
pathLenght = 0; | |
for (i = 0; i < len; i += 1) { | |
pathLenght += a.getAt(i).kmTo(a.getAt(i + 1)); | |
} | |
return pathLenght.toString().replace(NUMBER_DOT_TWONUMBERS, '$1$2'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment