Skip to content

Instantly share code, notes, and snippets.

@poltib
Created April 26, 2014 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poltib/11315885 to your computer and use it in GitHub Desktop.
Save poltib/11315885 to your computer and use it in GitHub Desktop.
gmap_script_distance
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