lat/long outward distance approx 800ft on each side from center.

**I have a central point of:**  

Latitude:38.6806353  

Longitude:-96.5001029

I am trying to resolve a formula with php how to get the latitude / longitude to the NWSE corners approx 800ft outward from a center point.

**So I would end up with a result similar to (but not correct):**

Central:  

38.6806353 -96.5001029  

N: 38.6806353 -96.5001029  

W: 38.6806353 -96.5001029  

S: 38.6806353 -96.5001029  

E: 38.6806353 -96.5001029  

I've been trying to reverse engineer a few Javascripts that I found, but having absolutly no luck.

Is there a php Class available that does this math or similar that would require minor revisions? I can't find one thus far...

**I found this function and I've been toying with it. I can get a nice array output like:**

```
Array ( [0] => -112.35301079549 [1] => 36.105603064867 [2] => -112.25722008867 [3] => 36.105603064867 )

```

But I can't get a N W S E coordinates set to generate? Anyone know what I am doing wrong with this? I need 4 sets of values instead of two like:

N: 38.6806353 -96.5001029  

W: 38.6806353 -96.5001029  

S: 38.6806353 -96.5001029  

E: 38.6806353 -96.5001029

```
<?php function getBoundingBox($lon_degrees,$lat_degrees,$distance_in_miles) { 

    $radius = 3963.1; // of earth in miles

    // bearings 
    $due_north = 0;
    $due_south = 180;
    $due_east = 90;
    $due_west = 270;

    // convert latitude and longitude into radians 
    $lat_r = deg2rad($lat_degrees);
    $lon_r = deg2rad($lon_degrees);

    // find the northmost, southmost, eastmost and westmost corners $distance_in_miles away
    // original formula from
    // http://www.movable-type.co.uk/scripts/latlong.html

    $northmost  = asin(sin($lat_r) * cos($distance_in_miles/$radius) + cos($lat_r) * sin ($distance_in_miles/$radius) * cos($due_north));
    $southmost  = asin(sin($lat_r) * cos($distance_in_miles/$radius) + cos($lat_r) * sin     ($distance_in_miles/$radius) * cos($due_south));

    $eastmost = $lon_r +   atan2(sin($due_east)*sin($distance_in_miles/$radius)*cos($lat_r),cos($distance_in_miles/$radius)-sin($lat_r)*sin($lat_r));
    $westmost = $lon_r + atan2(sin($due_west)*sin($distance_in_miles/$radius)*cos($lat_r),cos($distance_in_miles/$radius)-sin($lat_r)*sin($lat_r));

    $northmost = rad2deg($northmost);
    $southmost = rad2deg($southmost);
    $eastmost = rad2deg($eastmost);
    $westmost = rad2deg($westmost);

    // sort the lat and long so that we can use them for a between query        
    if ($northmost > $southmost) { 
        $lat1 = $southmost;
        $lat2 = $northmost;

    } else {
        $lat1 = $northmost;
        $lat2 = $southmost;
    }

    if ($eastmost > $westmost) { 
        $lon1 = $westmost;
        $lon2 = $eastmost;

    } else {
    $lon1 = $eastmost;
    $lon2 = $westmost;
    }

    return array($lon1,$lat1,$lon2,$lat1);
}
?>

```