【发布时间】:2015-07-31 08:53:52
【问题描述】:
我正在使用 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 我正在模拟器上检查它,我已经完成了调试>模拟位置>选项和模拟器调试>位置>Apple等设置。我跟着这个教程appcoda.com/how-to-get-current-location-iphone-user
标签: ios ios8 gps location core-location