I also have an equation that will calculate distance from zip x to zip y.
What I need to do is this:
Based on long / lat of a specified zip, figure the 'great circle' or lat / long values within x distance of the origin. This would work a heck of a lot better for what I'm trying to do, which is to calculate the distance from every long/lat in my database, and filter within the distance range. Example:
User-supplied zip code is at x.xx long and y.yy lat.
Calculate long and lat values 25 miles from the user-supplied zip code.
Query for zips within the long / lat values from the above equation (not based on matching zip codes).
Assitance would be appreciated!
Thanks,
Geoff B
distance = sqrt(x * x + y * y)
where x = 69.1 * (lat2 - lat1)
and y = 53.0 * (lon2 - lon1)
In any case, the square is defined where lat2 = lat1 for sides and lon2=lon1 for top/bottom. So, if you have distance and lat1 to solve for lat2:
distance = sqrt(69.1*(lat2-lat1)^2)
distance = sqrt((69.1*lat2 - 69.1*lat1)^2)
distance^2 = (69.1*lat2 - 69.1*lat1)^2
distance = (69.1*lat2 - 69.1*lat1)
distance + 69.1*lat1 = 69.1*lat2
(distance + 69.1*lat1)/69.1 = lat2
or
lat2 = (distance + 69.1*lat1)/69.1
likewise
lon2 = (distance + 53*lon1)/53
Now what you want is actually lat1 +- (lat2-lat1) so take lat2 subtract lat1 to get the change in lat and then add/subtract that from lat1 to get the two lats you need.
Make sense?
-Walden