如何從IOS中的用戶獲取當前位置?如何從IOS中的用戶獲得當前位置?
3 回答

PIPIONE
TA貢獻1829條經(jīng)驗 獲得超9個贊
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation *location = [locations lastObject]; NSLog(@"lat%f - lon%f", location.coordinate.latitude, location.coordinate.longitude);}
_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 }
#pragma mark - CLLocationManagerDelegate- (void)locationManager:(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ switch (status) { case kCLAuthorizationStatusNotDetermined: { NSLog(@"User still thinking.."); } break; case kCLAuthorizationStatusDenied: { NSLog(@"User hates you"); } break; case kCLAuthorizationStatusAuthorizedWhenInUse: case kCLAuthorizationStatusAuthorizedAlways: { [_locationManager startUpdatingLocation]; //Will update location immediately } break; default: break; }}
- 3 回答
- 0 關注
- 795 瀏覽
添加回答
舉報
0/150
提交
取消