简体   繁体   English

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

[英]How to find distance between two points using google maps geometry library?

I have attached the library我附上了图书馆

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

I have place A, with Latitude 30.694491 and longitude 76.665095 and place B with Latitude 30.7141289 and longitude 76.709398我有地方 A,纬度 30.694491,经度 76.665095,地方 B,纬度 30.7141289,经度 76.709398

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

i dont know how to add lat and long to above function???我不知道如何在上面的函数中添加 lat 和 long ??? i want the distance between 2 places!!!!我想要两个地方之间的距离!!!!

and also is it possible to find displacement between them????以及是否有可能在它们之间找到位移????

You need to create LatLng Objects.您需要创建 LatLng 对象。

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

computeDistanceBetween(_aCord, _bCord);

Use google.maps.geometry.spherical.computeDistanceBetween(a,b) to find distance between two points... read about computeDistanceBetween使用google.maps.geometry.spherical.computeDistanceBetween(a,b)找到两点之间的距离...... 阅读computeDistanceBetween

It's in meters它以米为单位

 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));
 <script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false&language=en"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM