I'm trying to figure out what would be most effective (relative to load time) to compare the distance between one zip code (which the user provides) and a whole bunch of other zip codes (there are about 200 zip codes right now, but its subject matter is increasing over time). I don't need anything exactly in the park.
I downloaded the zip code csv file for all of the USA and I have a function that produces the distance between two zip codes (in radians that I believe in.) I don't need to display the distance that I just need to sort 200 zip codes, the closest of them being the first of the results.
I uploaded the csv file to mysql table. I thought I could iterate over all 200 zip codes and update the field for each one containing the distance. Then, using ORDER BY, sort them from the nearest to the farthest.
Does anyone know a more efficient way to do this? This method would require updating all db zip codes every time a search query is executed. With only 200 zip codes it's not that hard, but I think it will slow down the load time as db is created. Thanks for any advice, it is very much appreciated!
source
share