如何通过Google Maps v3中的几何库指示点在圆形或矩形内? [英] How to indicate that a point is inside the circle or rectangle by geometry library in Google maps v3?

查看:53
本文介绍了如何通过Google Maps v3中的几何库指示点在圆形或矩形内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个:

if(google.maps.geometry.poly.containsLocation(new google.maps.LatLng(arrayLatitude[counter1], arrayLongitude[counter1]), polygon))
{
}

这是表明点在多边形内部或否的条件. 我正在寻找类似的东西,但要使用圆形或矩形.

This is the condition to indicates that a point is inside the polygon or no. I'm looking for something similar but for circle or rectangle.

类似这样的东西:

if(google.maps.geometry.circle.containsLocation(new google.maps.LatLng(arrayLatitude[counter1], arrayLongitude[counter1]), circle)
{
}

或者对于矩形:

if(google.maps.geometry.rectangle.containsLocation(new google.maps.LatLng(arrayLatitude[counter1], arrayLongitude[counter1]), rectangle)
{
}

推荐答案

矩形具有方法

getBounds()LatLngBounds返回此矩形的边界.

getBounds() LatLngBounds Returns the bounds of this rectangle.

尝试调用方法getBounds()返回 google.maps. LatLngBounds 项.它具有方法

Try call method getBounds() witch return google.maps.LatLngBounds item. It has method

contains(latLng:LatLng)boolean如果给定的lat/lng在此范围内,则返回true.

contains(latLng:LatLng) boolean Returns true if the given lat/lng is in this bounds.

类似

(new google.maps.Circle({center: new google.maps.LatLng(YOUR_LAT, YOUR_LNG),radius: YOUR_RADIUS})).getBounds().contains(google.maps.LatLng(POINT_LAT, POINT_LNG))

希望这就是您所需要的

这篇关于如何通过Google Maps v3中的几何库指示点在圆形或矩形内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆