Search code examples
iphonemkmapviewmapkitcllocation

Calculating a location coordinate a certain distance from another coordinate


I have a CLLoctionCoordinate2D and I want to figure out what the points are a given distance away from it. For an example, lets use 100 miles. So I want to computer the point 100 miles to the north, south, east, and west of it.

East and west are pretty easy. I converted both coordinates to MKMapPoints and used distanceInMeters*MKMapPointsPerMeterAtLatitude(latitude). This works fine for east and west because the latitude is constant.

However, this does not work for north and south. To the north, it underestimates and to the south it underestimates (because MKMapPointsPerMeterAtLatitude is changing as you move). How could I compute these points for the north and south?


Solution

  • There's 60 nautical miles per degree of latitude. This is also true for longitude, but at the equator only. To calculate the distance in longitude in nautical miles, multiply the distance in degrees longitude * 60nm * cos( latitude in radians ).

    Do the calculations of your new points (100 miles north, 100 miles south, etc.) in lat lon, not MKMapPoints, then convert your lat/lon (CLLocationCoordinate2D ?) points to MKMapPoints.