iOS - GeoCoder 地理编码
前言
NS_CLASS_AVAILABLE(10_8, 5_0)
@interface CLGeocoder : NSObject
地理编码
- 地名 -> 经纬度 等具体位置数据信息。根据给定的位置(通常是地名)确定地理坐标(经、纬度)。
反地理编码
- 经纬度 -> 地名。可以根据地理坐标(经、纬度)确定位置信息(街道、门牌等)。
1、GeoCoder 地理编码
配置
// 包含头文件
#import <CoreLocation/CoreLocation.h>
地理编码
// 声明 CLGeocoder 对象
@property (nonatomic, strong) CLGeocoder *geocoder; // 实例化 CLGeocoder 对象
self.geocoder = [[CLGeocoder alloc] init]; // 开始编码
[self.geocoder geocodeAddressString:self.addressField.text
completionHandler:^(NSArray *placemarks, NSError *error) { // 判断编码是否成功
if (error || 0 == placemarks.count) { NSLog(@"erroe = %@, placemarks.count = %ld", error, placemarks.count);
self.detailAddressLabel.text = @"你输入的地址找不到,可能在火星上"; } else { // 编码成功(找到了具体的位置信息) // 输出查询到的所有地标信息
for (CLPlacemark *placemark in placemarks) { NSLog(@"name = %@, locality = %@, country = %@", placemark.name, placemark.locality, placemark.country);
} // 显示最前面的地标信息
CLPlacemark *firstPlacemark = [placemarks firstObject]; self.longitudeLabel.text = [NSString stringWithFormat:@"%.2f", firstPlacemark.location.coordinate.longitude];
self.latitudeLabel.text = [NSString stringWithFormat:@"%.2f", firstPlacemark.location.coordinate.latitude]; self.detailAddressLabel.text = [NSString stringWithFormat:@"%@,%@,%@", firstPlacemark.name, firstPlacemark.locality, firstPlacemark.country];
}
}];
反地理编码
// 声明 CLGeocoder 对象
@property (nonatomic, strong)CLGeocoder *geocoder; // 实例化 CLGeocoder 对象
self.geocoder = [[CLGeocoder alloc] init]; // 创建 CLLocation 对象
CLLocation *location = [[CLLocation alloc] initWithLatitude:[self.latitudeField.text doubleValue]
longitude:[self.longtitudeField.text doubleValue]]; // 开始反编码
[self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) { // 判断反编码是否成功
if (error || 0 == placemarks.count) { NSLog(@"erroe = %@, placemarks.count = %ld", error, placemarks.count);
self.reverseDetailAddressLabel.text = @"你输入的经纬度找不到,可能在火星上"; } else { // 反编码成功(找到了具体的位置信息) // 输出查询到的所有地标信息
for (CLPlacemark *placemark in placemarks) { NSLog(@"name=%@, locality=%@, country=%@", placemark.name, placemark.locality, placemark.country);
} // 显示最前面的地标信息
CLPlacemark *firstPlacemark = [placemarks firstObject]; self.longtitudeField.text = [NSString stringWithFormat:@"%.2f", firstPlacemark.location.coordinate.longitude];
self.latitudeField.text = [NSString stringWithFormat:@"%.2f", firstPlacemark.location.coordinate.latitude]; self.reverseDetailAddressLabel.text = [NSString stringWithFormat:@"%@,%@,%@", firstPlacemark.name, firstPlacemark.locality, firstPlacemark.country];
}
}];
地理编码信息: placemark.name, // 地名
placemark.thoroughfare, // 街道
placemark.subThoroughfare, // 街道相关信息,例如门牌等
placemark.locality, // 城市
placemark.subLocality, // 城市相关信息,例如标志性建筑
placemark.administrativeArea, // 州
placemark.subAdministrativeArea, // 其他行政区域信息
placemark.postalCode, // 邮编
placemark.ISOcountryCode, // 国家编码
placemark.country, // 国家
placemark.inlandWater, // 水源、湖泊
placemark.ocean, // 海洋
placemark.areasOfInterest // 关联的或利益相关的地标 placemark.addressDictionary[@"City"]]; // 城市
placemark.addressDictionary[@"Country"]]; // 国家
placemark.addressDictionary[@"CountryCode"]]; // 国家编码
placemark.addressDictionary[@"FormattedAddressLines"][0]]; // 街道
placemark.addressDictionary[@"Name"]]; // 地名
placemark.addressDictionary[@"State"]]; // 州
placemark.addressDictionary[@"SubLocality"]]; // 城市相关信息
iOS - GeoCoder 地理编码的更多相关文章
- iOS地图 -- 地理编码和反地理编码
地理编码和反地理编码 用到的类和方法 CLGeocoder --> 地理编码管理器 - (void)geocodeAddressString:(NSString *)addressString ...
- IOS反地理编码取得城市名称
// 获取当前所在的城市名 CLGeocoder *reverseGeocoder=[[CLGeocoder alloc] init]; [reverseGeocoder reverseGeocode ...
- iOS开发拓展篇—CoreLocation地理编码
iOS开发拓展篇—CoreLocation地理编码 一.简单说明 CLGeocoder:地理编码器,其中Geo是地理的英文单词Geography的简写. 1.使用CLGeocoder可以完成“地理编码 ...
- 【iOS】7.4 定位服务->2.1.3.2 定位 - 官方框架CoreLocation 功能2:地理编码和反地理编码
本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正. 本文相关目录: ================== 所属文集:[iOS]07 设备工具 === ...
- iOS 原生地图地理编码与反地理编码
当我们要在App实现功能:输入地名,编码为经纬度,实现导航功能. 那么,我需要用到原生地图中的地理编码功能,而在Core Location中主要包含了定位.地理编码(包括反编码)功能. 在文件中导入 ...
- iOS之获取经纬度并通过反向地理编码获取详细地址
_locationManager = [[CLLocationManager alloc] init]; //期望的经度 _locationManager.desiredAccuracy = kCLL ...
- 猫猫学iOS 之CoreLocation反地理编码小Demo输入经纬度得到城市
猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243 一:效果 输入经纬度,能够得到相应的地名 二:思路 跟地里编码差 ...
- iOS地理反地理编码--CoreLocation
.sidebar{float:left;width:220px;} .container-fluid>.content{margin-left:240px;} a{color:#0069d6;t ...
- 在C#中通过使用Newtonsoft.Json库来解析百度地图地理编码(GeoCoder)服务接口返回的Json格式的数据
百度地图地理编码(GeoCoder)服务接口返回的Json格式的数据,如下所示: http://api.map.baidu.com/geocoding/v3/?address=**省**市**区**路 ...
随机推荐
- 日志时间格式有s,ms,us,如何排序最大10行
这个比较繁琐,谁有更好方法?告诉我 [root@module tmp]# cat oldboy.txt 12s120001ms12000000us13s[root@module tmp] ...
- splitFile2SmallFile
1. split file into several files """ this is aa customizable version of the standard ...
- Springmvc controller和jsp页面传值对象类型问题和普通问题
一:JSP-->controller 1.当jsp页面传递的值是对象类型时候比如User.name User.age的user对象传递,需要以下操作 jsp页面提供对应标签的value必须存在且 ...
- 夺命雷公狗-----React_native---2---sdk的安装
首先回到刚才的那个android的目录下,创建一个sdk文件夹 解压完成后目录结构如下所示: 然后就来设置环境变量,我们需要添加一个"ANDROID_HOME" 然后将这3个文件夹 ...
- html5,表单的综合案例
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- mac 10.11 cocopods注意的地方
最近安装cocoapods,遇到些新问题,安装过程纠结了一天,先是ruby版本的问题,解决掉了,后来又是ruby下载cocoapods慢的问题,尝试了好几遍都下载不成功.最后也是不断尝试和查询,算是安 ...
- Linux_know
Linux_know 在创建Linux分区时,一定要创建SWAP/根分区两个分区 Red Hat Linux 9中,系统默认的root用户对整个系统拥有完全的控制权. 当登录Linux时,一个具有唯一 ...
- [Silverlight]监听指定控件(FrameworkElement)的依赖属性(DependencyProperty)的更改
前言 转载请注明出处:http://www.cnblogs.com/ainijiutian 最近在silverlight项目使用Telerik的控件,遇到一个问题.就是使用RadBusyIndicat ...
- 赶时髦过了一遍Swift 语言....
Swift 语言 2014年6月3日发布,替代OBJECT-C Swift is a new programming language for creating iOS and OS X apps. ...
- ftp相关资料
一.ftp状态码 110 重新启动标记应答.在这种情况下文本是确定的,它必须是:MARK yyyy=mmmm,其中yyyy是用户进程数据流标记,mmmm是服务器标记. 120 ...