I have a point (lat, lng) X and a route drawn on the google map as shown below.
In my app, I have a rule:
If the distance between point X to the nearest point that is passed by the route is less than 5 meters, then the route can be traversed.
Otherwise, if the distance between points X to the closest point passed by the route is equal to or greater than 5 meters, then the route cannot be traversed.
Is this rule can be applied by using google map service?
The Google Maps Javascript API has a Geometry library.
The Geometry library has a isLocationOnEdge
function. See the documentation.
To determine whether a point falls on or near a polyline, or on or near the edge of a polygon, pass the point, the polyline/polygon, and optionally a tolerance value in degrees to
google.maps.geometry.poly.isLocationOnEdge()
. The function returns true if the distance between the point and the closest point on the line or edge falls within the specified tolerance. The default tolerance value is 10-9 degrees.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments