2014-06-12 2 views
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]; 
} 
+1

귀하의 질문이 명확하지 않습니다. 간결한 답변을 얻을 수있는 명확하게 명시된 질문을 포함하도록 편집하는 것이 좋습니다. –

+0

이전 실행에서 캐시 된 값일 수 있습니다. locationManager.location.timestamp를 확인하십시오. 지도보기의 showsUserLocation을 YES로 설정하여도 발생할 수 있습니다. 또한지도보기를 사용하여 사용자 위치를 표시하는 경우 CLLocationManager가 필요하지 않습니다. – Anna

답변

0

대부분의 경우 그것은지도보기 때문에 다음 줄의 현재 위치 업데이트를 요청 후 캐시 된 값입니다 : [self.mapView의 setShowsUserLocation가 : YES ];

관련 문제