Question

I have a customer that requires that a user can add his/her zip code, then an administrator can select users in specific area range

for example:

user - zip code
1    - 24533
2    - 56924
3    - 35993
4    - 13435

admin's zip code is 39824

He needs to select people in area range of 5 kilometers by zipcode. How can this happen using php or any other solutions?

Was it helpful?

Solution 2

php/mysql zip code proximity search

But, personally, I like the zip code range and distance calculation solution for you. If you had lat and long I would suggestion another but this seems to be similar to what you need.

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

OTHER TIPS

Very simple You just need the latitude and longitude of the zipcodes against which zipcode you want to get the zipcodes. If you not have longitude and latotude get it from google it is free. you can easily get latitude and longitude by zipcode.

For example you want to get the zipcodes round 100 mile of 'H8t'

i have a table of zipcodes having latitude and longitude info.

First i write a query to my table to get latitude and longitude

SELECT * FROM Tbl_Master_ZIPCodes WHERE ZIPcode ='H8T' 

after getting latitude and longitude i write a query below to get all zipcodes in the range of 100 miles of 'H8T'

SELECT distinct zipcode, 
3963 * (ACOS((SIN(45.456700/57.2958) * SIN(latitude/57.2958)) + (COS(45.456700/57.2958) * COS(latitude/57.2958) * COS(longitude/57.2958 - -73.712000/57.2958)))) AS distance 
FROM Tbl_Master_ZIPCodes 
WHERE 3963 * (ACOS((SIN(45.456700/57.2958) * SIN(latitude/57.2958)) + (COS(45.456700/57.2958) * COS(latitude/57.2958) * COS(longitude/57.2958 - -73.712000/57.2958)))) <= 100 Order by Distance 

If you are receiving address with the zip code, then you can query the Google geocode Api to get the geocode of these addresses.

Once you have these geocodes, calculating distance can be done using code sample from this site

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top