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

The Archive Base Latest Questions

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

I have an MKMapView that’s supposed to track the user’s location using a custom

  • 0

I have an MKMapView that’s supposed to track the user’s location using a custom view (not the blue dot). In order to substitute this view for the blue dot, I return it thusly:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    if (annotation == [mapView userLocation])
    {
        return userLocationView;
    }
}

To initialize tracking, I call

[mapView setShowsUserLocation: YES];
[mapView setUserTrackingMode: MKUserTrackingModeFollow animated: NO];
[mapView setDelegate: self];

As would be expected, -mapView:didUpdateUserLocation: gets called once when the app loads. Unfortunately, it’s never called again unless I change -mapView:viewForAnnotation: to have the following implementation:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    if (annotation == [mapView userLocation])
    {
        return nil;
    }
}

With these changes, the map loads the blue dot as the indicator of the user’s location, and -mapView:didUpdateUserLocation: gets called frequently, as would be expected.

Is there some sort of mutual exclusivity for tracking users’ locations and have a custom user location view? How can I make both happen?

Source

This project demonstrates this issue. https://dl.dropbox.com/u/2338382/MapKitFuckery.zip

Bug

This is most likely a bug, which I’ve filed as a radar. In the interim, the accepted answer should prove sufficient. However, it bears noting that I had to give up entirely on [mapView userLocation] and [mapView showsUserLocation], in favor of simply a custom annotation and the CLLocationManager.

  • 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-14T06:40:04+00:00Added an answer on June 14, 2026 at 6:40 am

    Instead of relying on the map view’s location updates, start a CLLocationManager, set its delegate and wait for -locationManager:didUpdateToLocation:fromLocation: (in iOS 5 and lower) or -locationManager:didUpdateLocations: (iOS 6). You will get much more reliable and plentiful information than using the map view’s delegate methods. You probably know the way to do this, but here it is:

    #import <CoreLocation/CoreLocation.h>
    
    - (void)viewWillAppear:(BOOL)animated
    {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
        [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
        [self.locationManager startUpdatingLocation];
    }
    
    // Deprecated in iOS 6
    - (void)locationManager:(CLLocationManager *)manager
        didUpdateToLocation:(CLLocation *)newLocation
               fromLocation:(CLLocation *)oldLocation
    {
    
        // Check the age of the newLocation isn't too long ago using newLocation.timestamp
    
        // Set the map dot using newLocation.coordinate
    
        // Set an MKCircle to represent accuracy using newLocation.horizontalAccuracy
    }
    

    I had a look at the delegate calls that come in to the mapView’s delegate, and returning anything other than nil stops calls to -mapView:didUpdateUserLocation:, like you said. Here are the calls in the order they arrive:

     - (void)mapViewWillStartLocatingUser:(MKMapView *)mapView
     - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
     - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation
     - (void)mapViewWillStartLoadingMap:(MKMapView *)mapView
     - (void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error
    

    Presumably the MKUserLocation object, not the MKMapView is the object responsible for calling the delegate with update calls. If you check the status of showsUserLocation and mapView.userLocation, they both look fine:

    NSLog(@"%d %@", mapView.showsUserLocation, mapView.userLocation);
    

    returns 1 and a non-nil object (1 <MKUserLocation: 0x1e02e580>). Maybe the mapView queries its userLocation object to get the current location, then sends it to the delegate. If that object has gone, it won’t work.

    It’s a bit strange, but like I said, you’ll get better updates from a CLLocationManager‘s updates.

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

Sidebar

Related Questions

I have a MKMapView and in the Map View Show User Location is set.
I have a view that I am using as an overlay on a MKMapView
I have a MKMapView & I use it to display user's current location. It
I have a MKMapView (obviously), that shows housing locations around the user. I have
I have an MKMapView that I am considering rotating in order to more conveniently
I have a created a custom class that extends from MKMapView and i want
I have a view controller with an MKMapView that calls [self.mapView setRegion:region animated:YES]; which
I have a view on the iPad that I'm adding an MKMapView to that
At the moment I have a view that contains an MKMapView. I also have
I have a map view with pins that when the user selects a pin

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.