2013-05-07 82 views
0

我想獲取用戶當前的位置,我發現該解決方案在計算器中:How to find your current location with CoreLocation。 但儘管這種解決辦法的我得到的消息上的NSLog: 2013-05-07 23:57:56.962 XXXXX[1951:c07] Latitude:(null),Longitude:(null)如何在獲取當前位置時避免空值?

這裏是我做了什麼:

在頭文件:

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

在FPGA實現:

- (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 2013-05-07 21:38:32