首页 > 代码库 > iOS下获取用户当前位置的信息
iOS下获取用户当前位置的信息
#import <MapKit/MKMapView.h>@interface ViewController (){ CLLocationManager *_currentLoaction; CLGeocoder *_geocoder; CLPlacemark *_placeMark;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _geocoder = [[CLGeocoder alloc] init]; _currentLoaction = [[CLLocationManager alloc] init]; _currentLoaction.delegate = self; [_currentLoaction startUpdatingLocation]; }#pragma mark - Location- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"locError:%@", error);}- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { CLLocationCoordinate2D locat = [newLocation coordinate]; double lattitude = locat.latitude; double longitude = locat.longitude; CLGeocodeCompletionHandler handler = ^(NSArray *placemark, NSError *error) { for (CLPlacemark *mark in placemark) { NSMutableDictionary *area_dic = [mark addressDictionary]; [area_dic setValue:[NSString stringWithFormat:@"%f", lattitude] forKeyPath:@"lattitude"]; [area_dic setValue:[NSString stringWithFormat:@"%f", longitude] forKeyPath:@"longitude"]; NSLog(@"area_dic is %@", area_dic); NSArray *array = [area_dic objectForKey:@"FormattedAddressLines"]; NSString *address = [area_dic objectForKey:@"FormattedAddressLines"]; NSLog(@"array is %@", array); address = [array objectAtIndex:0]; NSLog(@"address is %@", address); address = [area_dic objectForKey:@"City"]; NSLog(@"City is %@", address); } }; [_geocoder reverseGeocodeLocation:newLocation completionHandler:handler];}
iOS下获取用户当前位置的信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。