Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: iOS: How to use Boundings

  1. #1
    Etablierter skobbler
    Join Date
    04.07.2014
    Posts
    10

    iOS: How to use Boundings

    Hi,

    I found in the Reference site the SKBoundingBox Class Reference but how can I use this when I have multiple pins on the map and center the view in relation to the pins?


    Thank you

  2. #2
    Dev platform evangelist dandronic's Avatar
    Join Date
    31.03.2014
    Posts
    177
    Could you provide more details regarding what would you like to be able to do? Maybe SKBoundingBox is not the best solution

  3. #3
    Etablierter skobbler
    Join Date
    04.07.2014
    Posts
    10
    I want to display a map with multiple Annotations. So when the user see the map, it should zoom out/in, so all annotations are shown.

  4. #4
    Dev platform evangelist dandronic's Avatar
    Join Date
    31.03.2014
    Posts
    177
    We have an example covering custom annotations in our demo project (see the iOS demo project), and a chapter in our Getting Started covering "adding annotations".

    Are those sufficient or do you require something more?

  5. #5
    Etablierter skobbler
    Join Date
    04.07.2014
    Posts
    10
    I know how to add annotations. the point is, that I'm showing multiple annotiations in the map. And these are at other points. So when the user is in the Map View the zoom level should be so, that all annotations are shown.

  6. #6
    Dev platform evangelist dandronic's Avatar
    Join Date
    31.03.2014
    Posts
    177
    Ok - now I thing I understand the question - you would like to zoom the map so that all annotations are visible - is this correct?

  7. #7
    Etablierter skobbler
    Join Date
    04.07.2014
    Posts
    10
    Yes, that's correct

  8. #8
    Etablierter skobbler
    Join Date
    04.07.2014
    Posts
    10
    So, you cant help me ?

  9. #9
    Dev platform evangelist dandronic's Avatar
    Join Date
    31.03.2014
    Posts
    177
    So:
    You can achieve your scenario using the SKBoundingBox and the fitBounds:withPadding: method of the SKMapView like so:
    //let's assume we have a list of annotations
    NSArray *annotationList = @[self.annotation1, self.annotation2, self.annotation3];
    //next, we calculate the bounding box of the annotations
    //you can do this manually or use the boundingBoxIncludingLocation: method. We'll use boundingBoxIncludingLocation:
    //initialize the bounding box to enclose just the first annotation
    //iterate over all the annotations and use boundingBoxIncludingLocation: which will expand the box, eventually including all the annotations
    SKBoundingBox *box = [SKBoundingBox boundingBoxWithTopLeftCoordinate:self.annotation1. location bottomRightCoordinate:self.annotation1.location];
    for (SKAnnotation *annotation in annotationList) {
    box = [box boundingBoxIncludingLocation:annotation.location];
    }

    //use some padding so that the annotation icons at the edge of the box are visible
    [self.mapView fitBounds:box withPadding:CGSizeMake(50.0, 50.0)];

  10. #10
    Etablierter skobbler
    Join Date
    04.07.2014
    Posts
    10
    Quote Originally Posted by dandronic View Post
    So:
    You can achieve your scenario using the SKBoundingBox and the fitBounds:withPadding: method of the SKMapView like so:
    //let's assume we have a list of annotations
    NSArray *annotationList = @[self.annotation1, self.annotation2, self.annotation3];
    //next, we calculate the bounding box of the annotations
    //you can do this manually or use the boundingBoxIncludingLocation: method. We'll use boundingBoxIncludingLocation:
    //initialize the bounding box to enclose just the first annotation
    //iterate over all the annotations and use boundingBoxIncludingLocation: which will expand the box, eventually including all the annotations
    SKBoundingBox *box = [SKBoundingBox boundingBoxWithTopLeftCoordinate:self.annotation1. location bottomRightCoordinate:self.annotation1.location];
    for (SKAnnotation *annotation in annotationList) {
    box = [box boundingBoxIncludingLocation:annotation.location];
    }

    //use some padding so that the annotation icons at the edge of the box are visible
    [self.mapView fitBounds:box withPadding:CGSizeMake(50.0, 50.0)];
    boundingBoxIncludingLocation is not shown as a function?

    EDIT: Ok it's in the new Version. I will check the code now.

    EDIT2: It's not working. [self.mapView fitBounds:box withPadding:CGSizeMake(50.0, 50.0)]; does a strange behaviour. The map zooms like it's in zoomlevel 20, despite zoomlevel = 12.
    So.. maybe another solution?
    Last edited by MeltingElements; 16.07.2014 at 12:50.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •