'How to add bus routes on map and connect it with OSRM?

I am saving all bus routes data in my database. Whenever user requests if there is available routes from point A to point B, server should give the user response containing the available bus routes from point A to point B, and one more condition if there is no straight bus routes from point A to point B, then the response should give the available routes by transfers. So if there are no straight routes, first we need to find intersection point of route 1 and route 2, in which route 1 contains point A and route 2 contains point B. From A to Intersection point, and from Intersection point to point B.

I am saving route data as array of bus stops, and bus stops are consisting of latitude and longitude.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source