I'm hoping someone can point me to a convenient delegate method to answer the following question.
My question is: How do I know that the user has been located by MapKit for the first time?
When my view appears, I'd tell my MKMapView locate the user and set the map region around the user. After initially finding the user, I don't want to keep updating the map to his/her location. I want to give the user the freedom to pan around the map and not get automatically taken back to their location.
I'm having trouble when there's a delay in locating the user (for example, the very first time the user opens the app, MapKit doesn't locate the user until the he/she agrees to share their location). The result is that the map opens up somewhere over the Atlantic Ocean, and it doesn't correct itself once the user is found.
Unfortunately, -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation gets called a couple times before the user's real location has been determined (When testing, I see its NSLog statements before I ever agree to share my location).
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate=self;
}
-(void)viewWillAppear:(BOOL)animated{
[self.mapView setShowsUserLocation:YES];
[self.mapView setUserTrackingMode: MKUserTrackingModeNone];
hasUpdatedRegion=NO;
}
//MapKit Delegate Methods
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
NSLog(@"didUpdateUserLocation");
if(!hasUpdatedRegion)
{
hasUpdatedRegion=YES;
MKCoordinateSpan span=MKCoordinateSpanMake(0.3, 0.3);
MKCoordinateRegion currentRegion=MKCoordinateRegionMake(mapView.userLocation.coordinate, span);
[mapView setRegion:currentRegion];
}
}
-(void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated{
NSLog(@"didChangeTrackingMode");
}