doushi7394 2016-09-02 23:37
浏览 19
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • douqi0090 2016-09-02 23:49
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?