## Calculating polyline length

Showing 1-5 of 5 messages
 Calculating polyline length formazzasport 10/29/09 11:55 AM Is there some methods to calculate polyline length? thanks unk...@googlegroups.com 10/29/09 4:48 PM Re: Calculating polyline length Esa 11/2/09 7:27 PM That must be done segment by segment. First you need Haversine distance method equal to distanceFrom() of v2. There is an unexposed method LatLng.Hj() that looks exactly like that. However it returned invalid results. Finally I found out that there were radian conversions missing. I imitated that method but added those conversions.   google.maps.LatLng.prototype.kmTo = function(a){     var e = Math, ra = e.PI/180;     var b = this.lat() * ra, c = a.lat() * ra, d = b - c;     var g = this.lng() * ra - a.lng() * ra;     var 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;   } Then another method loops through the polyline and increments the final length using the previous method.   google.maps.Polyline.prototype.inKm = function(n){     var a = this.getPath(n), len = a.getLength(), dist = 0;     for(var i=0; i wrote: > any idea what might be wrong? I made some testing with IE7 and cannot reproduce the error. Script works with no errors. Even the parameter seem to have no effect with a single path polyline. A link to your page would be most informative.