I\'m building a web app (just for fun xD), in wich you can tell it where you are and where you want to go, and then you can search for a list of buses you may take.
My d
I think you'll have to do something like:
1) search the routes table for all points within X distance of the users desired destination, and for each, store into an array:
2) find the smallest distance for each bus_id, leaving a smaller array of a single point per bus_id (not sure exactly the best approach to this, but maybe some second query using distance, sorted ascending, limit 1)
3) walk through this array, searching for all points in the route table that are within X distance of the user start point, AND that have the bus_id being tested. put these in a second array
4) repeat step 2 on the end-point array
5) there should just now be one point for each bus_id in each array, so you could plot your polylines for each bus_id appearing in both set (if you have a very user friendly transit system there might be more than one)
Ok, let's get started, using query below you get nearest bus stops in certain radius (miles). Query will return every point within defined radius.
$lat = -31,52;
$lon = -68,52;
$multiplier = 112.12; // use 69.0467669 if you want miles
$distance = 10; // kilometers or miles if 69.0467669
$query = "SELECT *, (SQRT(POW((lat - $lat), 2) + POW((lng - $lng), 2)) * $multiplier) AS distance FROM routes WHERE POW((lat - $lat), 2) + POW((lng - $lng), 2) < POW(($distance / $multiplier), 2) ORDER BY distance ASC";
Result... nearest in 10 mile radius...
farthest but within 10 miles...
Now repeat the same for destination
, and then search your table for buses on that route.
Also check out this link... http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html