Search code examples
iphonecocoa-touchcore-locationlatitude-longitude

Moving a CLLocation by x meters


I have a CLLocation defined, and I'd like to move that point x meters to the east and y meters to the south. How may I achieve that?


Solution

  • There is a C function that is close to what you are asking but it takes a bearing and distance. It's in my UtilitiesGeo class on github. You would pass the latitude and longitude from your CLLocation to it and then create a new CLLocation from the resulting lat2 and lon2 that it returns:

    /*-------------------------------------------------------------------------
    * Given a starting lat/lon point on earth, distance (in meters)
    * and bearing, calculates destination coordinates lat2/lon2.
    *
    * all params in degrees
    *-------------------------------------------------------------------------*/
    void destCoordsInDegrees(double lat1, double lon1,
                             double distanceMeters, double bearing,
                             double* lat2, double* lon2);
    

    If you can't use that, take a look at the algorithms that it was derived from here and here and perhaps you can modify it or those sites might have something closer to your needs.