title: Finding Bounding Box from CLLocationCoordinate2D
body: <p>I am working with an API that allows me to specify a "bounding box" of coordinate which allows me to only return results within that box:</p>
  
  <ul>
  <li>Returns a list of geocaches inside the specified bounding box sorted
  by the distance from the center of the box. </li>
  <li>The parameters south
  latitude, west longitude, north latitude, east longitude define the
  edges of a bounding box. </li>
  <li>Coordinates should be in decimal degrees Use
  positive numbers for north latitude and east longitude and negative
  numbers of south latitude and west longitude. </li>
  <li>The box cannot cross
  the 180° longitude line or the 90° or -90° points.</li>
  </ul>
  
  <p>The math for this is a little beyond me, but I found somewhat helpful calculations, but I am not sure it is what I need for the API:</p>
  
  <pre><code>MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.mapView.centerCoordinate, 2000.0, 2000.0);
  CLLocationCoordinate2D northWestCorner, southEastCorner;
  northWestCorner.latitude  = center.latitude  - (region.span.latitudeDelta  / 2.0);
  northWestCorner.longitude = center.longitude + (region.span.longitudeDelta / 2.0);
  southEastCorner.latitude  = center.latitude  + (region.span.latitudeDelta  / 2.0);
  southEastCorner.longitude = center.longitude - (region.span.longitudeDelta / 2.0);
  </code></pre>
  
  <p>Does anyone know how I could do this? Are the calculations here not helpful in order to get the <code>west longitude, north latitude, east longitude</code> that define the edges of the bounding box?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The error I am getting:</p>
  
  <p><code>Invalid value for parameter: bbox=south,west,north,east</code></p>
  
  <p>Using the center value:</p>
  
  <p><code>center=37.552821,-122.377413</code></p>
  
  <p>Converted Box (after calculations from above):</p>
  
  <p><code>bbox=37.561831,-122.388730,37.543811,-122.366096</code></p>
  
  <p><strong>Final Working code:</strong></p>
  
  <pre><code>// Current distance
  MKMapRect mRect = mapView.visibleMapRect;
  MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect));
  MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect));
  CLLocationDistance distance = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint);
  
  // Region
  MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(request.center, distance, distance);
  CLLocationCoordinate2D northWestCorner, southEastCorner;
  northWestCorner.latitude  = request.center.latitude  + (region.span.latitudeDelta  / 2.0);
  northWestCorner.longitude = request.center.longitude - (region.span.longitudeDelta / 2.0);
  southEastCorner.latitude  = request.center.latitude  - (region.span.latitudeDelta  / 2.0);
  southEastCorner.longitude = request.center.longitude + (region.span.longitudeDelta / 2.0);
  base = [base stringByAppendingFormat:@"bbox=%f,%f,%f,%f&amp;", southEastCorner.latitude,northWestCorner.longitude,northWestCorner.latitude,southEastCorner.longitude];
  </code></pre>