Near location search on Google Maps, PHP & MySQL

后端 未结 2 1396
一向
一向 2021-02-04 21:58

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

2条回答
  •  -上瘾入骨i
    2021-02-04 22:08

    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...

    enter image description here

    farthest but within 10 miles...

    enter image description here

    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

提交回复
热议问题