您的位置:首页 > 移动开发 > IOS开发

IOS GPS(定位城市)

2015-11-03 10:07 447 查看
a.使用CoreLocation 定位得到经度和纬度

b.在-(void)locationManager:(CLLocationManager )manager didUpdateToLocation:(CLLocation )newLocation代理方法中使用CLGeocoder的reverseGeocodeLocation: :方法解析

c.在b中解析方法的完成回掉块completionHandler:^(NSArray *placemarks, NSError *error)中得到Country(国家) State(城市) SubLocality(区)

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

[locationManager stopUpdatingLocation];
NSLog(@"location ok");

CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark * placemark in placemarks) {

NSDictionary *test = [placemark addressDictionary];
//  Country(国家)  State(省)  SubLocality(区)城市需要用place mark.locality获得
NSLog(@"%@", [test objectForKey:@"State"]);
}
}];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: