如何计算谷歌地图中两点之间的距离?

问题描述:

我怎样才能计算两点之间的距离,在谷歌地图,我知道两点的纬度和longtutude ..

how can i calculate the distance between two points in google maps, where i know the latitude and longtutude of two points ..

我不想使用如果你有两个GLatLngs,你可以使用这个:
$ b

i don't want to use google direction api.

var miledistance, kmdistance;

miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1);
kmdistance = (miledistance * 1.609344).toFixed(1);

如果你有lat,lngs作为浮点数,你可以创建一些GLatLng来使用这个方法。例如

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);

邓肯。