-3

I want to create a bounding box for a geolocation in Swift which returns to me (minY maxY minX maxX) Is there a function to do this in Swift?

nevan king
  • 112,709
  • 45
  • 203
  • 241
pharaonil
  • 3
  • 2
  • 2
    Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please [see here](http://stackoverflow.com/help/how-to-ask) to learn how to write effective questions. – ielyamani Sep 12 '18 at 08:46
  • Hey, first of all welcome to stackoverflow. I would give you a hint as you are new. There is method point in view, get upper left point and translate it to coordinates. – Stefan Sep 12 '18 at 08:58

1 Answers1

0

iOS doesn't have the idea of a bounding box, but it does have a region struct called MKCoordinateRegion.

MKCoordinateRegion contains two things:

CLLocationCoordinate2D center;
MKCoordinateSpan span;

Both are structs. The span contains the height and width of the region. Using those you can make a bounding box (from here)

CLLocationCoordinate2D centerCoord = CLLocationCoordinate2DMake(41.145495, −73.994901);
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(centerCoord, 2000, 2000);

double latMin = region.center.latitude - .5 * startRegion.span.latitudeDelta;
double latMax = region.center.latitude + .5 * startRegion.span.latitudeDelta;
double lonMin = region.center.longitude - .5 * startRegion.span.longitudeDelta;
double lonMax = region.center.longitude + .5 * startRegion.span.longitudeDelta;

Edit: I just realised the request was for Swift. I'll leave translation as an exercise for bonus points.

nevan king
  • 112,709
  • 45
  • 203
  • 241