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

  • SEARCH
  • Home
  • 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 9163515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:27:57+00:00 2026-06-17T14:27:57+00:00

I have a MKMapView on my app. This is iOS6. -(void)viewDidLoad { ….. locationManager

  • 0

I have a MKMapView on my app. This is iOS6.

-(void)viewDidLoad
{
    .....
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"Update locations is hit");
    NSLog(@"379 the locations count is %d",locations.count);

    CLLocation *obj = [locations lastObject];
    NSLog(@"the lat is %f", obj.coordinate.latitude);
    NSLog(@"the long is %f", obj.coordinate.longitude);
    NSLog(@"the horizontal accuracy is %f",obj.horizontalAccuracy);
    NSLog(@"the vertical accuracty is %f",obj.verticalAccuracy);
    if (obj.coordinate.latitude != 0 && obj.coordinate.longitude != 0)
    {
        CLLocationCoordinate2D currrentCoordinates ;
        currrentCoordinates.latitude = obj.coordinate.latitude;
        currrentCoordinates.longitude = obj.coordinate.longitude;
    }
    ....more computation
    [locationManager stopUpdatingLocation];
}

When I first load the app, my location is showing little far away. Some times miles away. I also have a reset location button and if I click that map shows correct location. This is what I have in reset location button click:

- (IBAction)btnResetLocationClick:(UIButton *)sender
{
    locationManager = [[CLLocationManager alloc]init];
    locationManager.delegate = self;
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager startUpdatingLocation];
}

So how do I make the app get the correct current location on load up itself. Is there a way for the app to tell the map to wait for few milliseconds and then update. Or any other idea? Please let me know. If you need more information, please ask. Thanks.

  • 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-17T14:27:58+00:00Added an answer on June 17, 2026 at 2:27 pm

    What you could do is to:

    • do not turn off location services in didUpdateLocations automatically, but rather;
    • turn off location services in didUpdateLocations only if you’re sufficiently happy with the horizontalAccuracy; and
    • even if you don’t get the desired accuracy, turn off location services after a certain amount of time has passed.

    Thus, didUpdateLocations might look like:

    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
        CLLocation *location = [locations lastObject];
    
        // do whatever you want with the location
    
        // finally turn off location services if we're close enough
        //
        // I'm using 100m; maybe that's too far for you, but 5m is probably too small
        // as you frequently never get that accurate of a location
    
        if (location.horizontalAccuracy > 0 && location.horizontalAccuracy < 100)
            [locationManager stopUpdatingLocation];
    }
    

    And then in viewDidLoad, turn if off after a certain period of time has passed (you might want to check some status variable that you set if you’ve already turned off location services):

    -(void)viewDidLoad
    {
        .....
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        [locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
        [locationManager setDistanceFilter:kCLDistanceFilterNone];
        [locationManager startUpdatingLocation];
    
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 60.0 * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [locationManager stopUpdatingLocation];
        });
    }
    

    Original answer:

    I don’t see where you’re updating your map to be around your location. I’d expect to see something like:

    self.mapView.centerCoordinate = location.coordinate;
    

    or like:

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, 300, 300);
    [self.mapView setRegion:region];
    

    I’d also suggest, rather than turning off location services immediately (since frequently the first few locations are not that accurate), leave it on for a bit and let it hone in on your location until the horizontalAccuracy and verticalAccuracy fall within a certain predetermined limit. Look at those accuracy figures for a few calls to didUpdateLocations and you’ll see what I mean.

    I originally thought you were getting a negative horizontalAccuracy at which point I suggested implementing didFailToLocateUserWithError because according to horizontalAccuracy, “A negative value indicates that the location’s latitude and longitude are invalid.” Hopefully you get an error that describes what the issue is. Even if you’re not currently getting a negative horizontalAccuracy, you might want to implement this method, just to make sure you’re handling any errors correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within my app we have a screen with an MKMapView. This map shows pins
I have this following function implemented in my app There are no errors at
I have an app which is providing a zoomable MKMapView to the user. I
I have a MKMapView in a Contact Us section of my app. At the
In my viewDidLoad method, I have code to create a MKMapView, some constraints, and
I have custom annotation pin at app: - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
In the app I'm currently designing I have a MKMapView with overlays on it
I am developing an iOS app . Within this app i have a type
I am working on a app where I have to make Map using MKMapView
I have an iPhone app, it has two separate MKMapView components in different views,

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.