以km为单位的isLocationOnEdge容差计算 [英] isLocationOnEdge tolerance calculation in terms of km

查看:282
本文介绍了以km为单位的isLocationOnEdge容差计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用google map map API
isLocationOnEdge

  var isLocationNear = google.maps。 geometry.poly.isLocationOnEdge(latlng,new google.maps.Polyline({
path:google.maps.geometry.encoding.decodePath(result.routes [0] .overview_polyline)
}),.00001 );

我不知道宽容如何与公里相关

  isLocationOnEdge(point:LatLng,poly:Polygon | Polyline,tolerance?:number)

让sat我想要检测一个用户是否在100m内绘制在地图上的任何多段线。如何解决这个问题。

解决方案

这篇文章

它基于纬度和经度所需的小数位精度。



举例说明(33.00276,-96.6824)折线,如果公差为0.00001,那么如果您将点改为(33.00278,-96.6824),那么该点将在折线上。



,如果你想在折线约100m内找到一个位置,你可以使用0.001作为公差值。

例如,如果你的位置是(1.001, 12),折线中的一个点是(1,12),你的位置和折线之间的距离将是大约111.319米。 (1.001,12)和(1,12)之间的容差是0.001,所以 isLocationOnEdge()将返回true。



如果您的位置是(1.002,12),距离(1,12)的距离将是大约222.638米。它们之间的容差是0.02,所以如果使用0.001作为 isLocaitonOnEdge()的容差值,它将返回false。



您可以从此JSFiddle中看到示例代码: https://jsfiddle.net/j7cco3b0/1/


I am using google map map API
isLocationOnEdge

var isLocationNear = google.maps.geometry.poly.isLocationOnEdge(latlng, new google.maps.Polyline({
  path: google.maps.geometry.encoding.decodePath(result.routes[0].overview_polyline)
}), .00001);

I dnt understand how tolerance is related to km

isLocationOnEdge(point:LatLng, poly:Polygon|Polyline, tolerance?:number)

Let sat i want to detect if a user is within 100m for any polyline drawn on map. How to fix this.

解决方案

From one of the comments in this post:

tolerance, it is based on the decimal place accuracy desired in terms of latitude and longitude.

Example if say (33.00276, -96.6824) is on the polyline, if the tolerance is 0.00001 then if you change the point to (33.00278, -96.6824) then the point will ont be on the polyline.

So, you can probably use 0.001 as the tolerance value, if you want to find detect a location within about 100m for polyline.

For example, if your location is (1.001, 12), one of the points in polyline is(1, 12), the distance between your location and the polyline will be about 111.319 meters. The tolerance between (1.001, 12) and (1, 12) is 0.001, so the isLocationOnEdge() will return true.

If your location is (1.002, 12), distance to (1, 12), will be about 222.638 meters. The tolerance between them is 0.02, so if you use 0.001 as the tolerance value for isLocaitonOnEdge(), it will return false.

You can see the sample code from this JSFiddle: https://jsfiddle.net/j7cco3b0/1/

这篇关于以km为单位的isLocationOnEdge容差计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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