如何计算谷歌地图中两点之间的距离? [英] how to calculate distance between two points in google maps?
本文介绍了如何计算谷歌地图中两点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能计算两点之间的距离,在谷歌地图,我知道两点的纬度和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);
邓肯。
这篇关于如何计算谷歌地图中两点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文