You are not logged in.

- Topics: Active | Unanswered

**JoeMcManus****Member**- Registered: 2005-12-14
- Posts: 5

After my brief intro It's time I get this problem off my chest.

I'm into online mapping at the moment and have successfully been using the following formula to find 'nearest' whatevers based on someone's IP address mapped to a guesstimated but at region level fairly accurate latitude / longitude pair.

D= 6,370,997*arcos(sin(LAT1)*sin(LAT2) + cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))

WHERE:

D = distance in meters

LAT1 = latitude of point1 (in radians)

LONG1 = longitude of point1 (in radians)

LAT2 = latitude of point2(in radians)

LONG2 = longitude of point2 (in radians)

arcos = arc cosine

cos = cosine

sin = sine

and 6,370,997 is the radius of the sphere in meters.

Latitude and longitude can be converted from degrees to radians by dividing by 57.29577951

But now I have a different need for which I think I can re-use this formula by re-arranging the variables but for the life of me I can't work it out. Grammar school has been 6 years and it seems almost all gone!

Here's what I'd like to achieve and I'm hoping you could give me some directions.

The above gives me the distance between two lat/lon pairs. But now I want to provide the distance, say 250 Kilometers, and one lat/lon pair. What I need back is just four lat/lon pairs so I can draw a box around the base lat/lon, or 'centroid, if you like.

The 4 points can just be 12 o'clock, 3 o'clock, 6 o'clock and 9 o'clock if you think of the center of a clock as the given lat/lon pair. That should make it easy since that way you only need 3 different latitudes and 3 longitudes.

For 250Km the equation becomes:

250000 = 6370997 * arcos( sin( $lat1 ) * sin( $lat2 ) + cos( $lat1 * cos( $lat2 ) * cos( -1.7 - $long2 ) ) )

Or 250000 = 6370997 * 0.04 i.e.

0.04 = arcos( sin( $lat1 ) * sin( $lat2 ) + cos( $lat1 * cos( $lat2 ) * cos( -1.7 - $long2 ) ) )

$lat1 and $lon1 will be given, that's the 'centroid' I was talking about. For instance, if I base the calculations on the centroid being located in Little Rock, Arkansas that lat/lon could be:

Latitude: 34.750971

Longitude: -92.345512

Put a cross hair over that with lines 250km long north, east, south and west of the centroid and I get 4 lat/lon pairs on those simple axes.

But how? I've been trying to reverse engineer this for days in order to re arrange the elements but it doesn't help I learned Maths in Dutch and 12-6 years ago.

Can anyone guide me to the next step in solving this? Googling around didn't yield anything useful so I was hoping someone here would know their inverse cosine from their sines etc.

Thanks!

Offline

**JoeMcManus****Member**- Registered: 2005-12-14
- Posts: 5

Ironically, after posting all that I find I can buy the equation here: http://www.zipcodedownload.com/Products/Product/RadiusAPI/Standard/Overview/

I know, no fun in that but hey, it gets my script going! Sorry to be a timewaster...

Offline