php/mysql zip code proximity search

前端 未结 7 1982
南笙
南笙 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:23

    http://www.micahcarrick.com/04-19-2005/php-zip-code-range-and-distance-calculation.html

    I found this very awesome.

    "query the zip codes table for all the zip codes that fall within the radius then query the users table for all the users with the results(zip codes)"

    I found this is the best way to do it unless you need to put the users on a google map. If you're just listing the users in the mileage range it should be pretty easy to query the database (using the class) for a list of zips then select all users in those zipcodes.

    Select * from Users where zip_code IN (19125,19081,19107.........);
    

    That should do it.

提交回复
热议问题