text: # Calculate new coordinate x meters and y degree away from one coordinate
  
  I must be missing somthing out in the docs, I thought this should be easy...
  
  If I have one coordinate and want to get a new coordinate x meters away, in some direction. How do I do this?
  
  I am looking for something like
  
  ```-(CLLocationCoordinate2D) translateCoordinate:(CLLocationCoordinate2D)coordinate translateMeters:(int)meters translateDegrees:(double)degrees;```
  
  Thanks!
  
  Unfortunately, there's no such function provided in the API, so you'll have to write your own.
  
  This site gives several calculations involving latitude/longitude and sample JavaScript code. Specifically, the section titled "Destination point given distance and bearing from start point" shows how to calculate what you're asking.
  
  The JavaScript code is at the bottom of that page and here's one possible way to convert it to Objective-C:
  
  ``````- (double)radiansFromDegrees:(double)degrees
  {
  return degrees * (M_PI/180.0);
  }
  
  {
  }
  
  - (CLLocationCoordinate2D)coordinateFromCoord:
  (CLLocationCoordinate2D)fromCoord
  atDistanceKm:(double)distanceKm
  atBearingDegrees:(double)bearingDegrees
  {
  double distanceRadians = distanceKm / 6371.0;
  //6,371 = Earth's radius in km
  
  CLLocationCoordinate2D result;
  return result;
  }
  ``````
  
  In the JS code, it contains this link which shows a more accurate calculation for distances greater than 1/4 of the Earth's circumference.
  
  Also note the above code accepts distance in km so be sure to divide meters by 1000.0 before passing.
  
  • Thank you for you answer! Actually, I found a way of doing it. See my own answer. – Nicsoft Jul 9 '11 at 16:10
  • Good answer, I like this one because it deals directly with the coordinates and more completely answers the question as it takes the direction into account. – johnrechd Mar 16 '15 at 5:18
  
  I found one way of doing it, had to dig to find the correct structs and functions. I ended up not using degrees but meters for lat and long instead.
  
  Here's how I did it:
  
  ``````-(CLLocationCoordinate2D)translateCoord:(CLLocationCoordinate2D)coord MetersLat:(double)metersLat MetersLong:(double)metersLong{
  
  CLLocationCoordinate2D tempCoord;
  
  MKCoordinateRegion tempRegion = MKCoordinateRegionMakeWithDistance(coord, metersLat, metersLong);
  MKCoordinateSpan tempSpan = tempRegion.span;
  
  tempCoord.latitude = coord.latitude + tempSpan.latitudeDelta;
  tempCoord.longitude = coord.longitude + tempSpan.longitudeDelta;
  
  return tempCoord;
  
  }
  ``````
  
  And of course, if I really need to use degrees in the future, it's pretty easy (I think...) to do some changes to above to get it to work like I actually asked for.
  
  • simple and effective for my needs. Thanks! – vietstone Oct 22 '13 at 8:10
  • So how do you end up handeling the degrees ? – Sjoerd Perfors Dec 9 '14 at 9:29
  
  Using an `MKCoordinateRegion` has some issues—the returned region can be adjusted to fit since the two deltas may not exactly map to the projection at that latitude, if you want zero delta for one of the axes you are out of luck, etc.
  
  This function uses `MKMapPoint` to perform coordinate translations which allows you to move points around in the map projection's coordinate space and then extract a coordinate from that.
  
  ``````CLLocationCoordinate2D MKCoordinateOffsetFromCoordinate(CLLocationCoordinate2D coordinate, CLLocationDistance offsetLatMeters, CLLocationDistance offsetLongMeters) {
  MKMapPoint offsetPoint = MKMapPointForCoordinate(coordinate);
  
  CLLocationDistance metersPerPoint = MKMetersPerMapPointAtLatitude(coordinate.latitude);
  double latPoints = offsetLatMeters / metersPerPoint;
  offsetPoint.y += latPoints;
  double longPoints = offsetLongMeters / metersPerPoint;
  offsetPoint.x += longPoints;
  
  CLLocationCoordinate2D offsetCoordinate = MKCoordinateForMapPoint(offsetPoint);
  return offsetCoordinate;
  }
  ``````
  • This answer worked great for me and allowed me to convert a MapItem.placemark.region ( which was a CLCircularRegion; it has a radius given in meters) into a bounding box region – John Stricker Jan 21 '16 at 18:19
  
  Nicsoft's answer is fantastic and exactly what I needed. I've created a Swift 3-y version which is a little more concise and can be called directly on a `CLLocationCoordinate2D` instance:
  
  ``````public extension CLLocationCoordinate2D {
  
  public func transform(using latitudinalMeters: CLLocationDistance, longitudinalMeters: CLLocationDistance) -> CLLocationCoordinate2D {
  let region = MKCoordinateRegionMakeWithDistance(self, latitudinalMeters, longitudinalMeters)
  return CLLocationCoordinate2D(latitude: latitude + region.span.latitudeDelta, longitude: longitude + region.span.longitudeDelta)
  }
  
  }
  ``````
  • Might be better named `translate` since it is technically a translation not a transformation. – Dean Kelly Jan 24 '17 at 21:55
  • How can I make use of this if I know the angle? – Abin Baby Apr 25 '18 at 7:53
explanation: The document contains a math-related programming question and multiple answers to this question. The question asks how to calculate a new coordinate given a distance in meters and a direction in degrees from an initial coordinate. The answers provide different methods to achieve this, including a JavaScript solution converted to Objective-C and a more concise Swift 3 extension method.
distilabel_metadata.content: Evaluate the user given text extract and determine if it contains a math question and optionally and answer to this question.
  
  Output rules:
  
  1. Briefly describe the document and mention if it contains a question or a question and answer.
  2. Finalize the output with: Label: no-question,question,question-and-answer,multiple-question,multiple-question-and-answer
distilabel_metadata.role: system
distilabel_metadata.content: # Calculate new coordinate x meters and y degree away from one coordinate
  
  I must be missing somthing out in the docs, I thought this should be easy...
  
  If I have one coordinate and want to get a new coordinate x meters away, in some direction. How do I do this?
  
  I am looking for something like
  
  ```-(CLLocationCoordinate2D) translateCoordinate:(CLLocationCoordinate2D)coordinate translateMeters:(int)meters translateDegrees:(double)degrees;```
  
  Thanks!
  
  Unfortunately, there's no such function provided in the API, so you'll have to write your own.
  
  This site gives several calculations involving latitude/longitude and sample JavaScript code. Specifically, the section titled "Destination point given distance and bearing from start point" shows how to calculate what you're asking.
  
  The JavaScript code is at the bottom of that page and here's one possible way to convert it to Objective-C:
  
  ``````- (double)radiansFromDegrees:(double)degrees
  {
  return degrees * (M_PI/180.0);
  }
  
  {
  }
  
  - (CLLocationCoordinate2D)coordinateFromCoord:
  (CLLocationCoordinate2D)fromCoord
  atDistanceKm:(double)distanceKm
  atBearingDegrees:(double)bearingDegrees
  {
  double distanceRadians = distanceKm / 6371.0;
  //6,371 = Earth's radius in km
  
  CLLocationCoordinate2D result;
  return result;
  }
  ``````
  
  In the JS code, it contains this link which shows a more accurate calculation for distances greater than 1/4 of the Earth's circumference.
  
  Also note the above code accepts distance in km so be sure to divide meters by 1000.0 before passing.
  
  • Thank you for you answer! Actually, I found a way of doing it. See my own answer. – Nicsoft Jul 9 '11 at 16:10
  • Good answer, I like this one because it deals directly with the coordinates and more completely answers the question as it takes the direction into account. – johnrechd Mar 16 '15 at 5:18
  
  I found one way of doing it, had to dig to find the correct structs and functions. I ended up not using degrees but meters for lat and long instead.
  
  Here's how I did it:
  
  ``````-(CLLocationCoordinate2D)translateCoord:(CLLocationCoordinate2D)coord MetersLat:(double)metersLat MetersLong:(double)metersLong{
  
  CLLocationCoordinate2D tempCoord;
  
  MKCoordinateRegion tempRegion = MKCoordinateRegionMakeWithDistance(coord, metersLat, metersLong);
  MKCoordinateSpan tempSpan = tempRegion.span;
  
  tempCoord.latitude = coord.latitude + tempSpan.latitudeDelta;
  tempCoord.longitude = coord.longitude + tempSpan.longitudeDelta;
  
  return tempCoord;
  
  }
  ``````
  
  And of course, if I really need to use degrees in the future, it's pretty easy (I think...) to do some changes to above to get it to work like I actually asked for.
  
  • simple and effective for my needs. Thanks! – vietstone Oct 22 '13 at 8:10
  • So how do you end up handeling the degrees ? – Sjoerd Perfors Dec 9 '14 at 9:29
  
  Using an `MKCoordinateRegion` has some issues—the returned region can be adjusted to fit since the two deltas may not exactly map to the projection at that latitude, if you want zero delta for one of the axes you are out of luck, etc.
  
  This function uses `MKMapPoint` to perform coordinate translations which allows you to move points around in the map projection's coordinate space and then extract a coordinate from that.
  
  ``````CLLocationCoordinate2D MKCoordinateOffsetFromCoordinate(CLLocationCoordinate2D coordinate, CLLocationDistance offsetLatMeters, CLLocationDistance offsetLongMeters) {
  MKMapPoint offsetPoint = MKMapPointForCoordinate(coordinate);
  
  CLLocationDistance metersPerPoint = MKMetersPerMapPointAtLatitude(coordinate.latitude);
  double latPoints = offsetLatMeters / metersPerPoint;
  offsetPoint.y += latPoints;
  double longPoints = offsetLongMeters / metersPerPoint;
  offsetPoint.x += longPoints;
  
  CLLocationCoordinate2D offsetCoordinate = MKCoordinateForMapPoint(offsetPoint);
  return offsetCoordinate;
  }
  ``````
  • This answer worked great for me and allowed me to convert a MapItem.placemark.region ( which was a CLCircularRegion; it has a radius given in meters) into a bounding box region – John Stricker Jan 21 '16 at 18:19
  
  Nicsoft's answer is fantastic and exactly what I needed. I've created a Swift 3-y version which is a little more concise and can be called directly on a `CLLocationCoordinate2D` instance:
  
  ``````public extension CLLocationCoordinate2D {
  
  public func transform(using latitudinalMeters: CLLocationDistance, longitudinalMeters: CLLocationDistance) -> CLLocationCoordinate2D {
  let region = MKCoordinateRegionMakeWithDistance(self, latitudinalMeters, longitudinalMeters)
  return CLLocationCoordinate2D(latitude: latitude + region.span.latitudeDelta, longitude: longitude + region.span.longitudeDelta)
  }
  
  }
  ``````
  • Might be better named `translate` since it is technically a translation not a transformation. – Dean Kelly Jan 24 '17 at 21:55
  • How can I make use of this if I know the angle? – Abin Baby Apr 25 '18 at 7:53
distilabel_metadata.role: user
distilabel_metadata.raw_output_q_a_detector_0: The document contains a math-related programming question and multiple answers to this question. The question asks how to calculate a new coordinate given a distance in meters and a direction in degrees from an initial coordinate. The answers provide different methods to achieve this, including a JavaScript solution converted to Objective-C and a more concise Swift 3 extension method.
  
  Label: question-and-answer