isLocationOnEdge tolerance calculation in terms of km

google-maps, google-maps-api-3

Solution

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.002, so if you use number 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/

Problem

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.

Original source