title: Determining Midpoint Between 2 Coordinates
body: <p>I am trying to determine the midpoint between two locations in an <code>MKMapView</code>.  I am following the method outlined <a href="https://stackoverflow.com/q/4656802">here</a> (and <a href="https://stackoverflow.com/questions/4164830/geographic-midpoint-between-two-coordinates">here</a>) and rewrote it in Objective-C, but the map is being centered somewhere northeast of Baffin Island, which is no where near the two points.</p>
  
  <p>My method based on the java method linked above:</p>
  
  <pre><code>+(CLLocationCoordinate2D)findCenterPoint:(CLLocationCoordinate2D)_lo1 :(CLLocationCoordinate2D)_loc2 {
      CLLocationCoordinate2D center;
  
      double lon1 = _lo1.longitude * M_PI / 180;
      double lon2 = _loc2.longitude * M_PI / 100;
  
      double lat1 = _lo1.latitude * M_PI / 180;
      double lat2 = _loc2.latitude * M_PI / 100;
  
      double dLon = lon2 - lon1;
  
      double x = cos(lat2) * cos(dLon);
      double y = cos(lat2) * sin(dLon);
  
      double lat3 = atan2( sin(lat1) + sin(lat2), sqrt((cos(lat1) + x) * (cos(lat1) + x) + y * y) );
      double lon3 = lon1 + atan2(y, cos(lat1) + x);
  
      center.latitude  = lat3 * 180 / M_PI;
      center.longitude = lon3 * 180 / M_PI;
  
      return center;
  }
  </code></pre>
  
  <p>The 2 parameters have the following data:</p>
  
  <pre><code>_loc1:
      latitude = 45.4959839
      longitude = -73.67826455
  
  _loc2:
      latitude = 45.482889
      longitude = -73.57522299
  </code></pre>
  
  <p>The above are correctly place on the map (in and around Montreal).  I am trying to center the map in the midpoint between the 2, yet my method return the following:</p>
  
  <pre><code>latitude = 65.29055
  longitude = -82.55425
  </code></pre>
  
  <p>which somewhere in the arctic, when it should be around 500 miles south.</p>