[英]What is the Ideal way to create a Triangle-Coordinates in Google Map API with two location points consisting of latitude & longitude
I have a scenario in my JavaScript application where I have the coordinates of a starting point which consist of Latitude and Longitude, similarly an ending point with it's respective coordinates.我在我的 JavaScript 应用程序中有一个场景,其中我有一个起点的坐标,它由纬度和经度组成,类似的终点与它们各自的坐标。
Now I need to search for a location which basically provides with a set of coordinates and find if the recently entered location lies in between the previously mentioned starting point or ending point.现在我需要搜索一个基本上提供一组坐标的位置,并查找最近输入的位置是否位于前面提到的起点或终点之间。 However, the location does not need to match exactly within the points of the path of the start and end point.但是,该位置不需要在起点和终点的路径点内完全匹配。 That is even if the location lies around the distance of say 2-3 km from the derived path, it should give a match.也就是说,即使该位置距离派生路径大约 2-3 公里,它也应该匹配。
I believe that we can create a triangle by providing three coordinates ie start-point, end-point and a third point.我相信我们可以通过提供三个坐标来创建一个三角形,即起点、终点和第三个点。 So once the triangle is formed we can use google.maps.geometry.poly.containsLocation method to find if our searched location is present inside this triangle.所以一旦三角形形成,我们就可以使用 google.maps.geometry.poly.containsLocation 方法来查找我们搜索的位置是否存在于这个三角形内。
So my question is how can we get a third point to create a triangle which will provide locations that are nearby within 2-3 km from start to end point.所以我的问题是我们如何获得第三个点来创建一个三角形,该三角形将提供从起点到终点 2-3 公里内附近的位置。
Else is there any alternate approach to deal with my use case?否则有没有其他方法来处理我的用例?
Use googlemap's geometry library使用 googlemap 的几何库
This function specifically isLocationOnEdge这个函数具体是LocationOnEdge
Here's an example这是一个例子
0.001 tolerance value would be 100m 0.001 公差值为 100m
var isLocationNear = google.maps.geometry.poly.isLocationOnEdge(
yourLatLng,
new google.maps.Polyline({
path: [
new google.maps.LatLng(point1Lat, point1Long),
new google.maps.LatLng(point2Lat, point2Long),
]
}),
.00001);
Please note that the following answer assumes Plane Geometry where you should be using Spherical Geometry instead.请注意,以下答案假定为平面几何,您应该使用球面几何代替。 Although this will be fine for less accurate purposes (like approximate distance, etc..)尽管这对于不太准确的目的(例如近似距离等)来说是可以的。
It seems more of a geometry question than a programming question.它似乎更像是一个几何问题而不是一个编程问题。 A triangle like you mentioned won't be able to cover a straight line path in a uniform way.像您提到的三角形将无法以统一的方式覆盖直线路径。 The situation can be thought of more like a distance between point and a line problem (Refer the given diagram这种情况可以被认为更像是点和线之间的距离问题(参考给定的图表
Here you can just find the distance between point C and line AB which you can check whether it's below 2.5 KMs (I've omitted all the units and conversions for simplicity)在这里您可以找到点 C 和线 AB 之间的距离,您可以检查它是否低于 2.5 公里(为了简单起见,我省略了所有单位和转换)
Please note that you will also need to convert the distances from radian to appropriate units that you require using haversine formula, etc. which is not a trivial task ( https://www.movable-type.co.uk/scripts/latlong.html ).请注意,您还需要使用半正弦公式等将弧度的距离转换为您需要的适当单位,这不是一项微不足道的任务( https://www.movable-type.co.uk/scripts/latlong。 html )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.