Sunday, March 11, 2012

Code to calculate lat/lon given a lat/lon and distance?

My math skills are not up to it so I have to ask for it!
I need a procedure which accepts one lat, lon, and Distance(in feet? miles?)
and returns the lat's and lon's which describe a square around the given
lat/lon with 2 * Distance on a side. This will be used to search a database
for objects which fit within the given square. I can't draw it here, but the
given lat/lon would be at the center of the square. Any suggestions where I
might find an example? I have code to find the distance between two lat/lon'
s
but converting it is well beyond me.
Thanks,
MichaelPost DDL and some sample data, and we can help you find a solution.
ML|||> I need a procedure which accepts one lat, lon, and Distance(in feet? miles?)d">
> and returns the lat's and lon's which describe a square around the given
> lat/lon with 2 * Distance on a side.
Well, for starters, there's no such thing as a square on the surface of the
Earth. A square can only exist on a flat surface. So that leads us to...
How accurate does the result need to be?
And how large will the distance be, at max?
To get *really* accurate, you need to use spherical trig and a formula that
is really hairy.
But to get "reasonable" results--as in searching for all zip codes that are
within 50 miles of a given zip code--you can get away with approximating
things just using the pythagorean theorem ( a^2 + b^2 = c^2: square of the
hypotenuse of a right triangle is equal to the squares of the other two
sides).
Also, the number of miles per degree (or degrees per mile) will vary from
the North side of the "square" to the South side thereof. [Obvious when you
look at a globe: Near the poles, there are many fewer miles per degree than
there are at the equator.]

No comments:

Post a Comment