谷歌地图 - 如何获得米之间的两点之间的距离? [英] Google Maps - How to get the distance between two point in metre?
本文介绍了谷歌地图 - 如何获得米之间的两点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(45.463688,9.18814)
(46.0438317,9.75936230000002)
我需要(使用Google API V3,我认为)可以计算这两点之间的距离。我该怎么做?
解决方案
如果您想使用v3 google maps API,请使用以下函数:
注意:您必须将& libraries = geometry
添加到您的脚本源文件中
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false&libraries=geometry>< / script>
< script>
var p1 = new google.maps.LatLng(45.463688,9.18814);
var p2 = new google.maps.LatLng(46.0438317,9.75936230000002);
alert(calcDistance(p1,p2));
//计算km中
函数的两点之间的距离calcDistance(p1,p2){
return(google.maps.geometry.spherical.computeDistanceBetween(p1,p2)/ 1000).toFixed(2);
}
< / script>
I have these coordinate :
(45.463688, 9.18814)
(46.0438317, 9.75936230000002)
and I need (trought Google API V3, I think) to get the distance between those 2 points in metre. How can I do it?
解决方案
If you're looking to use the v3 google maps API, here is a function to use:
Note: you must add &libraries=geometry
to your script source
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script>
var p1 = new google.maps.LatLng(45.463688, 9.18814);
var p2 = new google.maps.LatLng(46.0438317, 9.75936230000002);
alert(calcDistance(p1, p2));
//calculates distance between two points in km's
function calcDistance(p1, p2) {
return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(2);
}
</script>
这篇关于谷歌地图 - 如何获得米之间的两点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文