how to calculate distance between two points in google maps?
how can i calculate the dist开发者_如何学运维ance between two points in google maps, where i know the latitude and longtutude of two points ..
i don't want to use google direction api.
If you have two GLatLngs, you can use this:
var miledistance, kmdistance;
miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1);
kmdistance = (miledistance * 1.609344).toFixed(1);
If you have the lat, lngs as floats you can just create some GLatLng's to use this method.. eg
var miledistance, kmdistance;
miledistance = new GLatLng(lat1,lng1).distanceFrom(new GLatLng(lat2, lng2), 3959).toFixed(1);
kmdistance = (miledistance * 1.609344).toFixed(1);
Duncan.
精彩评论