Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:03:09+00:00 2026-06-14T23:03:09+00:00

I’m trying to figure out how to reposition the MKMap region programmatically so that

  • 0

I’m trying to figure out how to reposition the MKMap region programmatically so that my annotation (automatically selected when the map loads) will all fit centered.

Current Result: https://www.evernote.com/shard/s46/sh/7c7d2ed8-203c-4878-af8c-83ff77ad7b21/ce7786acdf66b0782fc689b72d1b67e7

Desired Result: https://www.evernote.com/shard/s46/sh/21fb0eab-d5c4-4e6d-b05b-322e7dcce8ab/ab816f2a24f11b9c9e15bf55ac648f72

I have tried to reposition everything in - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views but that didn’t work. Is there a better approach?

// here is viewWillAppear logic

[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];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:03:11+00:00Added an answer on June 14, 2026 at 11:03 pm

    Following method will fit the map on region to show all annotations. You can call this method in Map’s didAddAnnotations method.

    - (void)zoomToFitMapAnnotations { 
    
        if ([mMapView.annotations count] == 0) return;
        int i = 0;
        MKMapPoint points[[mMapView.annotations count]];
    
        //build array of annotation points
        for (id<MKAnnotation> annotation in [mMapView annotations]){
             points[i++] = MKMapPointForCoordinate(annotation.coordinate);
        }
    
        MKPolygon *poly = [MKPolygon polygonWithPoints:points count:i];
        [mMapView setRegion:MKCoordinateRegionForMapRect([poly boundingMapRect]) animated:YES]; 
    }
    

    Howevcer you should see if you want to add user location annotation in visible area also. If you don’t then in loop check if current annotation is MkUserLocation and don’t add it’s points in points array.

    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        continue:
    }
    

    Now if you wanted an Annotation to be in center and selected automatically then do this

    annotation.coordinate=mMapView.centerCoordinate;
    [mMapView selectAnnotation:annotation animated:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.