Luc*_*ino 5 javascript math google-maps google-maps-api-3
各位大家好我/我知道这比gmap更像是一个数学问题,但我想有人已经通过了这个=)
在我的地图中,我有圈子(实际上我有几个,但这不会改变问题),如下所示:http://code.google.com/intl/pt-BR/apis/maps/articles/mvcfun/ step6.html步骤
如何知道标记(纬度X和经度Y)是否在此圆圈内?
抱歉英语不好,我是brazillian = p
在Google Maps JavaScript API v3中,您可以使用几何库.要启用它,您必须稍微更改脚本URL:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
Run Code Online (Sandbox Code Playgroud)
该库包含用于计算球体上几何数据的实用函数.你可以利用它来计算由latLngs给出的两点的距离:
var distanceInMetres = google.maps.geometry.spherical.computeDistanceBetween(latLngCircleCenter, latLngPoint);
Run Code Online (Sandbox Code Playgroud)
现在您可以轻松检查点是否在圆内(假设R以米为单位):
if(distanceInMetres < R)
alert("in the circle");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3977 次 |
| 最近记录: |