php/mysql zip code proximity search

前端 未结 7 1992
南笙
南笙 2020-12-02 15:08

I\'m just looking for suggestions on the best way to do this...

I need to create a search function that searches for \"users\" within a 50 mile radius of a zip code

7条回答
  •  孤街浪徒
    2020-12-02 15:10

    I would first do a search for all the zipcodes in the radius of the target. Then compare all the returned zipcodes to your user table zipcodes. Pull out the matching users.

    It find the zipcodes in a radius, found this MySQL call:

    $query = 'SELECT zzip FROM ' . table . 
                ' WHERE (POW((69.1*(zlongitude-"' . 
                $long . '")*cos(' . $long . 
                '/57.3)),"2")+POW((69.1*(zlatitude-"' . 
                $lat . '")),"2"))<(' . $radius . 
                '*' . $radius . ')';
    

    MySQL does all the math for you.

    I found a class that uses this here: http://www.nucleusdevelopment.com/code/do/zipcode

    Hope that helps.

提交回复
热议问题