Question

I am using Google Places API and direction API to mark the route between 2 places. I get a polyline for this route. Now I have another polyline which lies on this route.

Eg: Point A to point B -> initial polyline Point C to point D -> second polyline which lies on the A->B polyline.

Using isLocationOnEdge() method, I was able to find out if the C->D polyline lies on the A->B polyline or not.

Problem is I want to find out if the path C->D is in the direction of A->B or reverse. Is there any way to do this?

Was it helpful?

Solution

Using the geometry library, you have a computeHeading method available. Please see the documentation.

You could therefore compute the heading between points A and B and compare it with the heading of points C to D.

var heading = google.maps.geometry.spherical.computeHeading(path.getAt(0), path.getAt(1));

Where path is your first polyline. Then do the same for the second one and compare the results.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top