检查坐标是否在 google 地图的给定多边形中

Checking a co-ordinate is in the given polygon of google map

我已经在 google 地图上用预定义坐标创建了一个多边形。我想在我的网络服务中添加一个验证,它应该回答属于上述预定义多边形的那些用户。 为此,我获得了用户的地理位置,但如何检查该位置是否在多边形内。

使用 Google 地图几何库中的 containsLocation() API (doc here) :

HTML(注意库=几何):

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&signed_in=true&libraries=geometry&callback=initMap"
         async defer></script>

Javascript:

// e: your point
// polygon: a Google Map Polygon
if (google.maps.geometry.poly.containsLocation(e.latLng, polygon) {
   ...
}