Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have done something similiar to this to zoom out (or in) to an area that included a point annotation and the current location. You could expand this by looping through your annotations.</p> <p>The basic steps are:</p> <ul> <li>Calculate the min lat/long <br/></li> <li>Calculate the max lat/long <br/> </li> <li>Create CLLocation objects for these two points<br/></li> <li>Calculate distance between points<br/></li> <li>Create region using center point between points and distance converted to degrees <br/></li> <li>Pass region into MapView to adjust<br/> </li> <li>Use adjusted region to set MapView region<br/></li> </ul> <pre><code> -(IBAction)zoomOut:(id)sender { CLLocationCoordinate2D southWest = _newLocation.coordinate; CLLocationCoordinate2D northEast = southWest; southWest.latitude = MIN(southWest.latitude, _annotation.coordinate.latitude); southWest.longitude = MIN(southWest.longitude, _annotation.coordinate.longitude); northEast.latitude = MAX(northEast.latitude, _annotation.coordinate.latitude); northEast.longitude = MAX(northEast.longitude, _annotation.coordinate.longitude); CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude]; CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude]; // This is a diag distance (if you wanted tighter you could do NE-NW or NE-SE) CLLocationDistance meters = [locSouthWest getDistanceFrom:locNorthEast]; MKCoordinateRegion region; region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0; region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0; region.span.latitudeDelta = meters / 111319.5; region.span.longitudeDelta = 0.0; _savedRegion = [_mapView regionThatFits:region]; [_mapView setRegion:_savedRegion animated:YES]; [locSouthWest release]; [locNorthEast release]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload