I created a test application with only one view containing MKMapView and a controller that acts as a MapView delegate.
When I make a new assembly (completely removed from the device before reinstalling) and register callbacks, I see that mapView:didUpdateUserLocation
is called twice before the user indicates whether they want to show their current location or not.
MKUserLocation objects passed to the callback are not valid:
2012-03-13 08:20:17.518 MapTest[3325:707] Did update user location: 0.000000,0.000000 2012-03-13 08:20:17.581 MapTest[3325:707] Did update user location: 0.000000,0.000000
Is this the expected behavior for MKMapKit or error?
Update
I run this on my iPhone 4, not a simulator. Here is the controller code:
#import "ViewController.h" @implementation ViewController @synthesize mapView; - (void)viewDidLoad { [super viewDidLoad]; self.mapView.showsUserLocation = YES; self.mapView.delegate = self; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } -(IBAction)trackButtonTapped:(id)sender { self.mapView.showsUserLocation = !self.mapView.showsUserLocation; } #pragma mark - MKMapKitDelegate -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { NSLog(@"Did update user location: %f,%f", userLocation.coordinate.latitude, userLocation.coordinate.longitude); } -(void)mapViewWillStartLoadingMap:(MKMapView *)mapView { NSLog(@"Will start loading map"); } -(void)mapViewDidFinishLoadingMap:(MKMapView *)mapView { NSLog(@"Did finish loading map"); } -(void)mapViewWillStartLocatingUser:(MKMapView *)mapView { NSLog(@"Will start locating user"); } -(void)mapViewDidStopLocatingUser:(MKMapView *)mapView { NSLog(@"Did stop locating user"); } -(void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error { NSLog(@"Did fail loading map"); } -(void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error { if (error.code == kCLErrorDenied){ NSLog(@"User refused location services"); } else { NSLog(@"Did fail to locate user with error: %@", error.description); } } @end
source share