如何使用谷歌地图几何库找到两点之间的距离?

时间:2016-04-20 07:11:46

标签: javascript api google-maps

我已附上图书馆

<script type="text/javascript" src="http://maps.googleapis.com`/maps/api/js?libraries=geometry&sensor=false"></script>

我有A,纬度30.694491,经度76.665095 并且B的纬度为30.7141289,经度为76.709398

<script>
    computeDistanceBetween(from:LatLng, to:LatLng, radius?:number);
</script>

我不知道如何添加lat和long以上功能??? 我希望2个地方之间的距离!!!!

也可以找到它们之间的位移????

2 个答案:

答案 0 :(得分:0)

您需要创建LatLng对象。

var _aCord = new google.maps.LatLng(30.694491, 30.694491);
var _bCord = new google.maps.LatLng(30.7141289, 76.709398);

computeDistanceBetween(_aCord, _bCord);

答案 1 :(得分:0)

使用google.maps.geometry.spherical.computeDistanceBetween(a,b)查找两点之间的距离...... read about computeDistanceBetween

以米为单位

&#13;
&#13;
var a = new google.maps.LatLng(30.694491, 76.665095);
var b = new google.maps.LatLng(30.7141289, 76.709398);
console.log(google.maps.geometry.spherical.computeDistanceBetween(a,b));
alert(google.maps.geometry.spherical.computeDistanceBetween(a,b));
&#13;
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false&language=en"></script>
&#13;
&#13;
&#13;