1
CLLocationManager가 현재 위치 좌표를 얻는 방법을 이해할 수 없습니까? [locationManager startUpdatingLocation]을 호출하지 않고 locationManager.location.coordinate에 매개 변수를 설정하지 않은 경우locationManager는 좌표를 어떻게 가져 옵니까?
ViewController.h
@interface ViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property (weak, nonatomic) IBOutlet MKMapView* mapView;
@end
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
[self.mapView setShowsUserLocation:YES];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}
-(void) mapView:(MKMapView *) mv didAddAnnotationViews:(NSArray *)views {
MKCoordinateRegion region;
region = MKCoordinateRegionMakeWithDistance(locationManager.location.coordinate, 1000, 1000);
[mv setRegion:region animated:YES];
}
귀하의 질문이 명확하지 않습니다. 간결한 답변을 얻을 수있는 명확하게 명시된 질문을 포함하도록 편집하는 것이 좋습니다. –
이전 실행에서 캐시 된 값일 수 있습니다. locationManager.location.timestamp를 확인하십시오. 지도보기의 showsUserLocation을 YES로 설정하여도 발생할 수 있습니다. 또한지도보기를 사용하여 사용자 위치를 표시하는 경우 CLLocationManager가 필요하지 않습니다. – Anna