2013-05-07 2 views
0

사용자의 현재 위치를 가져오고 싶습니다. 그 해결책은 stackoverflow : How to find your current location with CoreLocation입니다. 하지만 해당 솔루션에도 불구하고 내가 Nslog에 그 메시지가 :현재 위치를 가져 오는 동안 null을 피하는 방법은 무엇입니까?

헤더 파일에서 :

#import <CoreLocation/CoreLocation.h> 
NSString *UsersCurrentLatitude; 
NSString *UsersCurrentLongitude; 
CLLocationManager *locationManager; 

실현하는 것이 지역 : 여기 2013-05-07 23:57:56.962 XXXXX[1951:c07] Latitude:(null),Longitude:(null)

내가 한 일이다

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view. 

     UsersCurrentLongitude:[NSString stringWithFormat:@"%f", locationManager.location.coordinate.longitude]; 
     UsersCurrentLatitude:[NSString stringWithFormat:@"%f", locationManager.location.coordinate.latitude]; 

      locationManager = [[CLLocationManager alloc] init]; 
      locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move 
      locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m 
      [locationManager startUpdatingLocation]; 

     NSLog(@"Latitude:%@,Longitude:%@",UsersCurrentLatitude,UsersCurrentLongitude); 

} 

답변

1

여기 단계가 누락되었습니다. 위치 서비스를 시작한 다음 위임자로부터 위치를 가져와야합니다. exemple from Apple 또는 tutorial을 살펴 보시기 바랍니다.

+0

감사합니다. – ananana