php/mysql zip code proximity search

前端 未结 7 1984
南笙
南笙 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:16

    The lat/long you have for each zip code is a geographic center for that zip, right? So if you first find zip codes with geographic centers within 50 miles, then users in those zip codes, you could easily be returning users more than 50 miles away. So you'd sacrifice some accuracy doing it that way.

    But if you have a lot of users (more than the number of zip codes), this would be faster, since you'd query against the smaller zip codes table first. And you could index zip codes in the users table, so finding users with a particular zip code would be fast.

    Just some thoughts! So, if you are expecting a lot of users and the radius of 50 miles doesn't need to be exact, I would find zip codes within 50 miles, then users within those zip codes.

提交回复
热议问题