Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you programmatically position the mkmapregion to fit annotation
    primarykey
    data
    text
    <p>I'm trying to figure out how to reposition the MKMap region programmatically so that my annotation (<em>automatically selected when the map loads</em>) will all fit centered.</p> <p>Current Result: <a href="https://www.evernote.com/shard/s46/sh/7c7d2ed8-203c-4878-af8c-83ff77ad7b21/ce7786acdf66b0782fc689b72d1b67e7" rel="nofollow">https://www.evernote.com/shard/s46/sh/7c7d2ed8-203c-4878-af8c-83ff77ad7b21/ce7786acdf66b0782fc689b72d1b67e7</a></p> <p>Desired Result: <a href="https://www.evernote.com/shard/s46/sh/21fb0eab-d5c4-4e6d-b05b-322e7dcce8ab/ab816f2a24f11b9c9e15bf55ac648f72" rel="nofollow">https://www.evernote.com/shard/s46/sh/21fb0eab-d5c4-4e6d-b05b-322e7dcce8ab/ab816f2a24f11b9c9e15bf55ac648f72</a></p> <p>I have tried to reposition everything in <code>- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views</code> but that didn't work. Is there a better approach?</p> <p>// here is viewWillAppear logic</p> <pre><code>[self.mapView removeAnnotations:self.mapView.annotations]; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; CLGeocodeCompletionHandler completionHandler = ^(NSArray *placemarks, NSError *error) { if (error) { EPBLog(@"error finding placemarks: %@", [error localizedDescription]); } else { if (placemarks) { [placemarks enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { CLPlacemark *placemark = (CLPlacemark *)obj; if ([placemark.country isEqualToString:@"United States"]) { EPBAnnotation *annotation = [EPBAnnotation annotationWithCoordinate:placemark.location.coordinate]; annotation.title = self.locationObj.locationName; annotation.subtitle = self.locationObj.locationAddress; [self.mapView addAnnotation:annotation]; self.mapView.selectedAnnotations = @[annotation]; [self.mapView setCenterCoordinate:placemark.location.coordinate]; /** * @todo * MOVE THIS OUTTA HERE */ MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}}; region.center = placemark.location.coordinate; region.span.longitudeDelta = 0.003f; region.span.latitudeDelta = 0.003f; [self.mapView setRegion:region animated:YES]; [self.mapView regionThatFits:region]; *stop = YES; } }]; } } }; [geocoder geocodeAddressString:self.locationObj.locationAddress completionHandler:completionHandler]; </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.
 

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