In my MapView
in a button tap I run the following action:
- (IBAction)locate:(id)sender event:(UIEvent*)event {
DLog(@"");
if ([self.mapView respondsToSelector:@selector(userTrackingMode)]) {
[self.mapView setUserTrackingMode:MKUserTrackingModeNone];
}
[self.mapView setShowsUserLocation:NO];
[self.mapView setShowsUserLocation:YES];
}
I see the userLocation pin
and call the following method to change the map position:
- (void) resizeRegionToFitAllPins:(BOOL)includeUserLocation animated:(BOOL)animated {
if ([self.annotations count] == 1) {
NSObject<MKAnnotation> *annotation = [self.annotations objectAtIndex:0];
BOOL isUserLocation = [annotation isKindOfClass:MKUserLocation.class];
if ((includeUserLocation && isUserLocation) ||
isUserLocation == NO) {
CLLocationCoordinate2D coordinate;
coordinate.latitude = annotation.coordinate.latitude;
coordinate.longitude = annotation.coordinate.longitude;
[self setRegion:MKCoordinateRegionMake(coordinate, MKCoordinateSpanMake(0.001f, 0.001f)) animated:animated];
}
}
}
My problem is that the map is updating the user's position forever (in loop). It is impossible to use the map after activating the user's location. What is necessary to make it stop updating the user's position and allow user to use map?
The method mapView:didUpdateUserLocation:
is called over and over again.
I Put the MKMapViewDelegate
on the interface, set the self.mapView.delegate
to self and set the mapViewWillStartLocatingUser:
and mapViewDidStopLocatingUser:
with only a Dlog(@"")
call;
The mapViewDidStopLocatingUser:
is not called ever.
- (void)mapView:(MKMapView *)map didUpdateUserLocation:(MKUserLocation *)userLocation {
DLog(@"Resizing...");
[self.mapView resizeRegionToFitAllPins:YES animated:YES];
}
}
- (void)mapViewWillStartLocatingUser:(MKMapView *)mapView {
DLog(@"");
}
- (void)mapViewDidStopLocatingUser:(MKMapView *)mapView {
DLog(@"");
}