【发布时间】:2015-12-03 08:08:05
【问题描述】:
我想获取用户当前的位置和地址,我使用CLLocationManager 并添加了核心位置框架。但反应是什么。请分享您的 cmets。
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self; [locationManager startUpdatingLocation];
代表是
(void)locationManager:(CLLocationManager *)manager didFailWithError: (NSError *)error {
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *currentLocation = locations.first;
[locationManager setDelegate:nil];
if (currentLocation != nil) {
NSString *longitudeLabel = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
NSString *latitudeLabel = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
}
【问题讨论】:
-
你用的是哪个iOS版本?
-
看下面我的回答
标签: ios objective-c iphone geolocation cllocationmanager