我如何知道一个圆圈中是否包含Lat,Lng点?

编程入门 行业动态 更新时间:2024-10-24 08:21:33
本文介绍了我如何知道一个圆圈中是否包含Lat,Lng点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好的很自我解释。我正在使用谷歌地图,我试图找出经纬度是否在半径的圆圈内,例如x(x由用户选择)。

边界框对此不起作用。我已经尝试使用以下代码:

distlatLng = new google.maps.LatLng(dist.latlng [0],dist .latlng [1]); var latLngBounds = circle.getBounds(); if(latLngBounds.contains(distlatLng)){ dropPins(distlatLng,dist.f_addr); }

这仍然会导致标记位于圆圈之外。

我猜这是一些简单的数学需要计算的曲率或面积,但我不知道从哪里开始。任何建议?

解决方案

我真的有点傻。考虑它,我们可以使用Pythagorus定理。

距离一个点(X英里)和两个纬度和两个经度有一个最大距离。如果我们用这些形成一个三角形,那么我们就可以求出距离这个点的距离。

所以我们知道 point1 坐标为 lat1,lng1 为圆心, point2 坐标为 lat2, lng2 是我们试图决定的点是否在圆圈中。

我们用一个由 point1 和 point2 。这 point3 的坐标是 lat1,lng2 或 lat2,lng1

我们必须将所有内容翻译成米,以便Google地图可以正常运行,因此英里乘以1609(大约)和纬度/经度的乘积111000(约)。这不完全准确,但它确实有足够的工作。

希望一切都合理。

Ok pretty self explanatory. I'm using google maps and I'm trying to find out if a lat,long point is within a circle of radius say x (x is chosen by the user).

Bounding box will not work for this. I have already tried using the following code:

distlatLng = new google.maps.LatLng(dist.latlng[0],dist.latlng[1]); var latLngBounds = circle.getBounds(); if(latLngBounds.contains(distlatLng)){ dropPins(distlatLng,dist.f_addr); }

This still results in markers being places outside the circle.

I'm guess this is some simple maths requiring the calculation of the curvature or an area but I'm not sure where to begin. Any suggestions?

解决方案

I've been a bit silly really. Thinking about it we can use Pythagorus' theorem.

We have a maximum distance away from a point (X miles), and two latitudes and two longitudes. If we form a triangle using these then we can solve for the distance from the point.

So say we know point1 with coordinates lat1,lng1 is the center of the circle and point2 with coordinates lat2,lng2 is the point we are trying to decide is in the circle or not.

We form a right angled triangle using a point determined by point1 and point2. This, point3 would have coordinates lat1,lng2 or lat2,lng1 (it doesn't matter which). We then calculate the differences (or if you prefer) distances - latDiff = lat2-lat1 and lngDiff = lng2-lng1

we then calculate the distance from the center using Pythagorus - dist=sqrt(lngDiff^2+latDiff^2).

We have to translate everything into meters so that it works correctly with google maps so miles are multiplied by 1609 (approx) and degrees of latitude/longitude by 111000 (approx). This isn't exactly accurate but it does an adequate job.

Hope that all makes sense.

更多推荐

我如何知道一个圆圈中是否包含Lat,Lng点?

本文发布于:2023-11-09 10:17:26,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:圆圈   Lat   Lng

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!