根据物理位置计算可能的旅程匹配

I need your help. I have a database table called 'journeys' which contains (fromlat, fromlng, tolat, tolng) and I also have another table called 'cityPostcodes' which contains (postcode, lat, lng).

Users can search journeys by just entering 'from postcode' and 'to postcode'. After mapping these postcodes to their actual physical locations, I want to calculate likely journey matches based upon these postcodes.

What I am struggling is, how to check if two journeys are heading to the same direction? for example, the journey searched by the user and those in the 'journeys' table.

You could use something like the geospatial extension for PHP to calculate the cardinal direction of the from/to lat/long coordinates to see if they head in the same cardinal direction.

You would need an origin latitude/longitude set of coordinates and a destination lat/long for each journey. You can then using something like the Haversine formula or Vincenty's formulae to calculate distince and derive the cardinal North/South/East/West direction of the line segments along the ellipsoid.