Problem-->
Given a zip code (i.e. 90210), find all the zip codes within a given radius (10 miles).
Brainstorm-->
So, I've read up a couple of different threads on this, namely
here and
here.
But I still find myself scratching my head and want to walk away in
frustration. There doesn't seem to be a 1-2-3 process to do this.
I suppose I should establish some initial conditions:
I'm using SQL Server 2008 R2, but the table does not utilize spatial
data. It does contain centroid (lng/lat) point for each zip and it can
also map zip code boundaries. Instead of using spatial data to map the
zip code boundary, however, it uses many, many longitude and latitude
points.
So, let's say I map a circle on a map, where the circle has a radius of
10 miles. So, area = pi * r^2 = pi * (10 miles * 1609.344 meters / 1
mile)^2 = 258998811.0336pi meters and circumference = 32186.88pi
meters.
However, since this is a map of Planet Earth, we're talking about a 3-D image mapped onto a 2-D plane, and straight 2-D formulas may not be entirely accurate or correct, perhaps. Furthermore, the area and circumference of the circle don't reveal a wealth of information about its coordinates within. I can have an infinite amount of coordinates on a circle and certainly inside of it.
So, where and how should I be devoting my time and efforts? Should I be looking for where the circle touches the zip code region (i.e. polygon) or where the circle touches the centroid of the zip (i.e. lat/lng), based on the information given above?
With either method, I am not entirely confident as to how to proceed and what formula(s) to use. With the centroids, I'd have to calculate the radius from the center of the circle to every centroid of every zip code in the database and return those which are less-than-or-equal to that of the circle's. If that is the case, that seems like it's computationally expensive. Is there a more efficient way?
If I use the polygons, and unless someone knows of a way to convert typical float/decimal to spatial data, this seems complex and I'm not even sure where to start. I suppose I'd have to figure out the bounds of the polygon and then make some determination about if edge of the circle contains all or part of this polygon. That all sounds good, in theory. But how do I apply that to the google maps api and sql?
Thank you.