I’m ploting a route between two points and I need to check if the route goes through a predefiend location. In the api, each GStep has a start and end points but the path doesn’t have to be straight. Given a Lat/Long point, is there a way to check if it intersects with a route?
Share
You should be able to get the individual vertices of the polyline generated by
GDirectionsvery easily. First you have to make sure to pass thegetPolyline: trueoption when you call theGDirections.load()if you do not attach theGDirectionsto the map. Then you can simply iterate through each vertex of the polyline, and then you should probably check if your point is within a certain distance threshold from your predefined location.Consider the following example:
You could probably improve this method by skipping some steps that are definitely too far from your test point. You could get the polyline index of each route step with the
getPolylineIndex()method. This can help you restricting your for loop to a narrower set of vertices.Further reading and reference: