简体   繁体   English

在 Google Map API 中创建三角形坐标的理想方法是什么,其中两个位置点由纬度和经度组成

[英]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.

相关问题 在谷歌地图中根据纬度和经度绘制三角形 - Draw triangle based on latitude and longitude in google map 限制Google API Map中经度和纬度返回的小数点数 - Limit the number Of Decimal Points Returned on Longitude and Latitude in Google API Map 如何将Google地图集中到纬度和经度位置? - How to center a Google Map to a latitude and longitude location? 在Google Map Api上显示经度和纬度 - Displaying Latitude and Longitude on Google Map Api 显示位置使用经度/纬度坐标 - Google地图 - Display location Using Longitude/Latitude Coordinates - Google Maps 使用标记从Google地图获取纬度/经度坐标 - Get latitude/longitude coordinates from a Google map using a marker 获取Google Maps JS API上两个点之间(按百分比)的点的纬度和经度? - Getting the latitude and longitude of the point in between (by percentage) two points on Google Maps JS API? 通过街道地址获取谷歌地图的坐标(纬度和经度) - 角度 - get the coordinates(latitude and longitude) of google map by street address - angular 如何在Google地图上将标记的像素位置映射到经度和纬度 - How to map the pixel location of a marker on Google Map to Latitude and Longitude 如何通过Google Map API将经度和纬度值设置为其他位置? - How to set the longitude and latitude values to other location from google map api?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM