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 6903771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:58:01+00:00 2026-05-27T07:58:01+00:00

I have an MKMapView as part of a Navigation Controller in a Tab Bar

  • 0

I have an MKMapView as part of a Navigation Controller in a Tab Bar based app.

I click a UIButton on the first View Controller and it pushes to the second View Controller which contains the MKMapView. When the Map View loads, it zooms in on the user’s location using:

- (void)mapView:(MKMapView *)theMapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    if ( !initialLocation )
    {
        self.initialLocation = userLocation.location;

        MKCoordinateRegion region;
        region.center = theMapView.userLocation.coordinate;
        region.span = MKCoordinateSpanMake(2.0, 2.0);
        region = [theMapView regionThatFits:region];
        [theMapView setRegion:region animated:YES];
    }
}

When I hit the back button on the Navigation Controller above the MapView and then click back to the map, it no longer zooms in on the user’s current location, but just has the full zoom out default:

Here’s a picture of the view the second time.

I figure it would work correctly if I could somehow call the didUpdateUserLocation in the viewDidAppear method but I’m not sure how to pull this off since the didUpdateUserLocation is a delegate method.

Is that the right approach or is there a different approach I should take to do this? Thanks!

P.S. I’ve seen this question but it’s slightly different with it’s use of a modal view controller

  • 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-05-27T07:58:02+00:00Added an answer on May 27, 2026 at 7:58 am

    I would pull all of the zooming code into its own method that can be messaged from -viewDidAppear: and -mapView:didUpdateToUserLocation:.

    - (void)zoomToUserLocation:(MKUserLocation *)userLocation
    {
        if (!userLocation)
            return;
    
        MKCoordinateRegion region;
        region.center = userLocation.location.coordinate;
        region.span = MKCoordinateSpanMake(2.0, 2.0); //Zoom distance
        region = [self.mapView regionThatFits:region];
        [self.mapView setRegion:region animated:YES];
    }
    

    Then in -viewDidAppear:…

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        [self zoomToUserLocation:self.mapView.userLocation];
    }
    

    And in the -mapView:didUpdateToUserLocation: delegate method…

    - (void)mapView:(MKMapView *)theMapView didUpdateToUserLocation:(MKUserLocation *)location
    {
        [self zoomToUserLocation:location];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MKMapView . Sometimes after my view controller is dismissed, I'll get
I have a tabbar application and on the first tab I have a MKMapView
I have two views. The first is a MKMapView with some annotations. Clicking a
I have a detail view that includes three UIButtons, each of which pushes a
I have an MKMapView in my app and have a button that turns on
In the app I'm currently designing I have a MKMapView with overlays on it
I am making an app that has an MKMapView. I have a translucent UIToolbar
I have an application that uses MKMapView and at some point in the app
I have a problem using the -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccesoryControlTapped:(UIControl *)control method. I
I have a MKMapView with it's delegate set to my controller (m) class. Code

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.