确定位置是否位于Google地图中的某个区域内 [英] Determine if location is within a certain region in Google Map

查看:234
本文介绍了确定位置是否位于Google地图中的某个区域内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在上面显示的G​​oogle地图中,有2个绿色箭头指向的标记。它们是由蓝色圆圈以虚线表示的2个不同区域的中心。由橙色箭头指向的标记位于上述区域之一。



这带来了一个问题。



假设数据库中有一长串地区中心位置,并且所有地区的固定半径都相同。 我如何执行计算,以便系统可以告诉我Google Map上的任意位置是否位于至少一个区域内?使用来遍历区域列表对于 -loop或而源代码中的 -loop不是一个选项,因为性能是我应用程序中的第一优先级。



是否有任何现有的Google Map API或库提供这些功能?

我要使用Ionic for client和.NET C#作为服务器,如果它很重要的话。

您可以使用 Google Maps Geometry Library



如果该区域是一个圆圈,则可以计算距中心的距离,例如参见SO:
何w检测一个点是否在Circle中?



如果该区域是Polygon,请参阅此示例: https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation


In the Google Map shown above, there are 2 markers pointed by green arrows. They are the centers of 2 different regions indicated by blue circles in dotted lines. The marker pointed by an orange arrow lies within one of the aforementioned areas.

This brings up a problem.

Suppose there is a long list of locations of region center in the database, and all regions have the same fixed radius. How can I implement the computation such that the system can tell me whether an arbitrary location on Google Map lies within at least one of the regions? Iterating through the list of regions with a for-loop or while-loop in the source code is not an option, as performance is the first priority in my application.

Are there any existing Google Map APIs or libraries which provide such functionalities?

I am going to use Ionic for client and .NET C# for server, if it matters.

解决方案

You can use Google Maps Geometry Library.

If the area is a circle you can calculate the distance from the center, see for example on SO: How to detect if a point is in a Circle?

If the area is a Polygon see this example: https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation

这篇关于确定位置是否位于Google地图中的某个区域内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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