私MapView
のボタンタップでは、次のアクションを実行します。
- (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];
}
を確認しuserLocation pin
、次のメソッドを呼び出してマップの位置を変更します。
- (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];
}
}
}
私の問題は、マップがユーザーの位置を永遠に (ループで) 更新していることです。ユーザーの位置情報をアクティブ化した後、マップを使用することはできません。ユーザーの位置の更新を停止し、ユーザーがマップを使用できるようにするには何が必要ですか?
メソッドmapView:didUpdateUserLocation:
は何度も呼び出されます。をMKMapViewDelegate
インターフェイスに配置し、self.mapView.delegate
を self に設定し、mapViewWillStartLocatingUser:
andを呼び出しmapViewDidStopLocatingUser:
のみで設定します。Dlog(@"")
はmapViewDidStopLocatingUser:
呼び出されません。
- (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(@"");
}