使用Google Maps API检查点是否在Polygon内 [英] Check if a point is inside a Polygon with the Google Maps API

查看:167
本文介绍了使用Google Maps API检查点是否在Polygon内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Google Maps API v3的应用程序,并且我很努力地知道如何确定一个X坐标是否在一个多边形内。

I am developing an application using the Google Maps API v3, and I'm struggling to know how to find out if an X coordinate is inside a polygon.

推荐答案

您可以使用几何库 Google Maps JS API。有一个叫做 containsLocation 的函数,它告诉你给定的LatLng是否在 Polygon 中。请注意,它是一个多边形,而不是一条多段线。 Polyline是(正如它在名称中所说)一条线。所以在折线内没有这样的东西。您可以使用 containsLocation 函数检查一个点是否在Polygon中。

You can use the Geometry Library of the Google Maps JS API. There's a function called containsLocation which tells you if a given LatLng is inside a Polygon. Note that it's a Polygon, not a Polyline. A Polyline is (as it says in the name) a line. So there is no such thing as a point being inside a polyline. You can check if a point is inside a Polygon with the containsLocation function.

google.maps.geometry.poly.containsLocation(somePoint, somePolygon)

这篇关于使用Google Maps API检查点是否在Polygon内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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