1

I'm doing this in Python (3) but this could be a more general question.

Basically what I'm trying to achieve is getting a list of surrounding zip codes, next to a certain zip code, and the range is dynamic. So what zip codes are around say zip code 90210, within a 20 mile radius. And I need to query a SQL DB for my results.

So I need to calculate 2 lat, lang points, that create a rectangular search area (yes its not completely accurate because its not circular but that is not a big deal), so something like this:

P1 (lat, long) -------------------------+
|                                       |
|                                       |
|                                       |
|          Original (lat, long)         |
|                                       |
|                                       |
|                                       |
-------------------------- P2 (lat, long)
"radius" given = 30 miles 

So all we have as input is the lat, long, radius, need to calculate P1 and P2. Since my math is well, in high school, I would love some help with this. Also need to consider that this is in Miles, whatever the formula for Lat, Long is for Miles (not KM)

geocodezip
  • 158,664
  • 13
  • 220
  • 245
veryxcit
  • 419
  • 1
  • 3
  • 8
  • See the query in [the article "Creating a Store Locator with PHP, MySQL & Google Maps" in the Google Maps Documentation](https://developers.google.com/maps/articles/phpsqlsearch_v3#findnearsql) – geocodezip Feb 18 '16 at 18:41
  • Possible duplicate of [How to calculate the bounding box for a given lat/lng location?](https://stackoverflow.com/questions/238260/how-to-calculate-the-bounding-box-for-a-given-lat-lng-location) – iled Mar 12 '18 at 09:41

1 Answers1

1

Doing a little research on Google Earth and marking points across the USA (I assume USA given that you refer to ZIP codes) I can approximate that on average 1° of latitude equates to 68.97 miles or 70 miles and 1° of longitude equates to 55.77 miles or 56 miles.

Therefore for a 30 mile square (note: not radius) you would need to search +/- 0.43° or 26' latitude and +/- 0.54° or 32' longitude.

So to complete your answer:

P1 = Origin + 0°26'N, Origin + 0°32'W
P2 = Origin - 0°26'N, Origin - 0°32'W

Note these are approximate values but should give satisfactory results accross the USA.

Colin Dickie
  • 910
  • 4
  • 9
  • Thanks Colin, that makes a lot of sense, but I guess what I'm looking for (and I should've been more specific) is the python way of doing it or pseaudocode.I have as inputs a point with lat and long and a radius in miles. So original_lat, original_long, radius are the variables. and what I need to claculate is p1_lat, p1_long and p2_lat, p2_long. That way I can query my database with comparison operators. – veryxcit Feb 21 '16 at 20:28
  • I'm afraid I don't follow. I've basically provided the pseudo code. Would you like me to code your utility from scratch? – Colin Dickie Feb 22 '16 at 00:51