iOS【根据经纬度获取地名,根据地名获取经纬度】

30 篇文章 0 订阅

1. 根据经纬度获取地名

[objc]  view plain  copy
  1. CLGeocoder *clGeoCoder = [[CLGeocoder alloc] init];  
  2. [clGeoCoder reverseGeocodeLocation:newLocation completionHandler: ^(NSArray *placemarks,NSError *error) {  
  3.      for (CLPlacemark *placeMark in placemarks)  
  4.      {  
  5.          NSDictionary *addressDic=placeMark.addressDictionary;  
  6.            
  7.          NSString *state=[addressDic objectForKey:@"State"];  
  8.          NSString *city=[addressDic objectForKey:@"City"];  
  9.          NSString *subLocality=[addressDic objectForKey:@"SubLocality"];  
  10.          NSString *street=[addressDic objectForKey:@"Street"];  
  11.            
  12.          [self stopLocation];  
  13.          [_chooseCityBtn setTitle:city forState:UIControlStateNormal];  
  14.          [_activityIndicator stopAnimating];  
  15.      }  
  16.        
  17.  }];  

2. 根据地名获取经纬度

[objc]  view plain  copy
  1. NSString *oreillyAddress = @"1005 Gravenstein Highway North, Sebastopol, CA 95472, USA";  
  2. CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];  
  3. [myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *placemarks, NSError *error) {  
  4.     if ([placemarks count] > 0 && error == nil) {  
  5.         NSLog(@"Found %lu placemark(s).", (unsigned long)[placemarks count]);  
  6.         CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];  
  7.         NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude);  
  8.         NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude);  
  9.     }  
  10.     else if ([placemarks count] == 0 && error == nil) {  
  11.         NSLog(@"Found no placemarks.");  
  12.     } else if (error != nil) {  
  13.         NSLog(@"An error occurred = %@", error);  
  14.     }  
  15. }];  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值