0

I have CLLocationCoordinate2D and some radius in meters. I would like to get two bounding coordinates (top-right and bottom-left) of the area.

Shmidt
  • 15,652
  • 16
  • 79
  • 129
  • The trigonometry in the linked answer might be unnecessary for your case. [This approach](http://stackoverflow.com/a/2409582/467105) might be simpler. –  Aug 04 '14 at 11:39

1 Answers1

3

If I understand you correctly you want to location these 2 red squares:

enter image description here

Thanks to the code you that can find here the implementation is pretty simple:

    CLLocationCoordinate2D cc0 = coordinate;
    CLLocationCoordinate2D cc1 = [self coordinateFromCoord:cc0 atDistanceKm:circleRadius atBearingDegrees:45];
    CLLocationCoordinate2D cc2 = [self coordinateFromCoord:cc0 atDistanceKm:circleRadius atBearingDegrees:225];
    NSLog(@"%.5f,%.5f -> %.5f,%.5f AND %.5f, %.5f", cc0.latitude, cc0.longitude, cc1.latitude, cc1.longitude, cc2.latitude, cc2.longitude);
Community
  • 1
  • 1
Szu
  • 2,203
  • 1
  • 18
  • 35
  • I was looking for the coordinates of the external square, but I think I can figure it out by myself with your code. Thanks! – Shmidt Aug 04 '14 at 11:34
  • Sorry, I didn't understand last comment. I think the simplest is to calculate new radius as hypotenuse of the triangle. – Shmidt Aug 04 '14 at 11:44
  • Did you mean to replace ```double distanceRadians = distanceKm / 6371.0;``` from the other post? – Shmidt Aug 04 '14 at 11:45
  • Ah right it is the quickest way to do that. But if you have some time you can just add distance calculated into radians to the center point and adjust toLonRadians to be in the range -180 to +180. – Szu Aug 04 '14 at 11:51
  • 1
    Anyway I deleted that comment because I paste wrong calculation. Angle = distanceInMeters / 6371000; // Earth radius = 6371km – Szu Aug 04 '14 at 11:52