Thanks! If I understand it right, this returns the distance between two coordinates? How to do if I have an array of several coordinates from a walking path that I want to measure?
On 3 Juli, 12:08, Bost <[email protected]> wrote: > On Jul 2, 9:06 pm, 3D-kreativ <[email protected]> wrote: > > > Hi, > > > I wonder if it's possible to measure a distance from a starting point > > to an end point from an array of coordinates? > > I am using the following function: > > /** > * Get the geodetic distance of two points in km. > * <br>The geodetic line is the shortest distance of 2 points on a > sphere. > * @param latlng1 geographical latitude, longitude of point 1 in > degrees > * @param latlng2 geographical latitude, longitude of point 2 in > degrees > * @return geodetic distance in km. > * @seehttp://en.wikipedia.org/wiki/Great-circle_distance > */ > function geoDistance(latlng1,latlng2){ > var lat1=latlng1.lat()*toRadians; > var lng1=latlng1.lng()*toRadians; > var lat2=latlng2.lat()*toRadians; > var lng2=latlng2.lng()*toRadians; > var dlat=lat2 - lat1; > var dlng=lng2 - lng1; > var z=Math.sin(dlat*0.5); > var x=z*z; > z=Math.sin(dlng*0.5); > x+=z*z*Math.cos(lat1)*Math.cos(lat2); > var ds=2*Math.asin(Math.sqrt(x)); > return ds*earthRadius;} > > Regards, > Bost -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
