我使用iOS8上,並使用下面的代碼用於獲取經度和緯度通過GPS獲得在iOS8上的經度和緯度:無法通過GPS
-(void)CurrentLocationIdentifier
{
locationManager = [CLLocationManager new];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 &&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedWhenInUse)
//[CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways)
{
// Will open an confirm dialog to get user's approval
[locationManager requestWhenInUseAuthorization];
//[_locationManager requestAlwaysAuthorization];
} else {
[locationManager startUpdatingLocation]; //Will update location immediately
}
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations lastObject];
NSLog(@"lat%f - lon%f", location.coordinate.latitude, location.coordinate.longitude);
}
- (void)locationManager:(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status) {
case kCLAuthorizationStatusNotDetermined: {
NSLog(@"User still thinking..");
}
case kCLAuthorizationStatusDenied: {
NSLog(@"User hates you");
} break;
case kCLAuthorizationStatusAuthorizedWhenInUse:
case kCLAuthorizationStatusAuthorizedAlways: {
[locationManager startUpdatingLocation]; //Will update location immediately
} break;
default:
break;
}
}
運行此代碼我收到輸出的日誌後:用戶還在想。任何人都可以幫我解決這個問題我是iOS和CoreLocation.Framework的新手? 請幫我找到錯誤,我該如何解決這個問題。
你是在模擬器還是真實設備上檢查這個? –
@TapasPal我正在模擬器上檢查它,並且已經完成了設置,如調試>模擬位置>選項和模擬器調試>位置>蘋果。我跟着這個教程http://www.appcoda.com/how-to-get-current-location-iphone-user/ – Sushrita