vangheem / pyzipcode

revive the pyzipcode project!
MIT License
14 stars 11 forks source link

Is zipcode radius calculation wrong? #18

Open thavidu opened 10 months ago

thavidu commented 10 months ago

In these few lines: https://github.com/vangheem/pyzipcode/blob/6056689c1249fdb96841fd17bf9b281fade3cc1c/pyzipcode/__init__.py#L135C47-L135C47 Which calculates zipcodes near other zipcodes, are latitude and longitude accidentally swapped around?

According to: https://www.geographyrealm.com/latitude-longitude/

Lines of latitude are called parallels and in total there are 180 degrees of latitude. The distance between each degree of latitude is about 69 miles (110 kilometers).

The distance between longitudes at the equator is the same as latitude, roughly 69 miles. At 45 degrees north or south, the distance between is about 49 miles (79 km).

However the code searches for a +/- 69 in Longitude and +/- 49 in Latitude, shouldn't it be the other way around? (or am I crazy?)

also the search is a bit off since 49 miles is only correct at 45-degrees, whereas the US spans roughly from 28th to 49th parallels, but that one is harder to fix

thavidu commented 10 months ago

Found a more accurate implementation here: https://github.com/MacHu-GWU/uszipcode-project/blob/21242cad7cbb7eaf73235086b89499bd90c36531/uszipcode/search.py#L515C48-L515C48