0

I have the next routes:

enter image description here

The red one is goes from A to B, the blue one goes from A' to B' and the green one goes from A'' to B''. I have the lat/long for A,B, A', B', A'' and B'' (I'm using Google Maps API) and I want to know if there is an algorithm to determinate if two routes have the same direction.

For example, in the picture, the red and blue route have the same direction.

Marcos
  • 4,643
  • 7
  • 33
  • 60

1 Answers1

1

Find the bearing of B from A. Movable-type's page is the standard reference.

However you can also use the geometry library in Google Maps API v3:

var a = new google.maps.LatLng(...);
var b = new google.maps.LatLng(...);
var bearing = google.maps.geometry.spherical.computeHeading(a,b)
Andrew Leach
  • 12,945
  • 1
  • 40
  • 47
  • Thanks. I've tried your solution but I don't know how to interpret the result. For example I have the next routes: http://maps.google.es/maps/ms?msid=213382632638333022283.0004c066e422c7c2c6735&msa=0 and the bearing from A to B returns 347.8, the bearing from A' to B' returns 328.17 and the bearing from B' to A' returns 148.16. I'm using this implementation: http://stackoverflow.com/q/2232911/434171 – Marcos May 19 '12 at 17:26
  • On your map, the bearing of B from A is not the same as the bearing of B' from A'. Part of the route AB appears parallel to part of the route A'B', but you need to test the separate parts of the route. Your bearings appear correct (albeit from an unusual zero direction). – Andrew Leach May 21 '12 at 15:15