我正在使用CLLocationManager來獲取用戶的當前位置。我需要用戶的當前位置,因爲我正在使用Open Weather API來顯示用戶所在的天氣數據。我的問題是,我第一次打開應用lat和long值是0,0。但是,如果我再次運行應用程序,它工作正常。所以只有在應用程序首次啓動時纔會使用不正確的lat和long值。我盡我全部設立在viewDidLoad中,這裏是代碼...Latidude和經度是不正確的首次啓動應用程序ios
locationManager = [[CLLocationManager alloc] init];
[locationManager requestAlwaysAuthorization];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
[self->locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
我不知道我做錯了。是否在視圖控制器而不是App Delegate中獲得lat和long?
這裏是我如何獲取位置值:
locationManager.location.coordinate.latitude
locationManager.location.coordinate.longitude
該代碼不顯示如何獲取和處理位置值。我建議你也分享一下。另外,它是模擬器還是真實設備? –
好吧現在就發佈這個代碼。我正在使用一個實際的設備。儘管在模擬器和設備上都會發生此錯誤。 –
你是說這兩行跟在同一塊/方法內的前面的代碼行? –