iOS地址编码解析
- (void)viewDidLoad
{
[super viewDidLoad];
// 创建地址解析器
self.geocoder = [[CLGeocoder alloc] init];
}
- (IBAction)encodeTapped:(id)sender
{
// 获取用户输入的地址字符串
NSString* addr = self.addrField.text;
if(addr != nil && addr.length > 0)
{
[self.geocoder geocodeAddressString:addr
completionHandler: ^(NSArray *placemarks, NSError *error)
{
// 如果解析结果的集合元素的个数大于1,表明解析得到了经度、纬度信息
if (placemarks.count > 0)
{
// 只处理第一个解析结果,实际项目中可使用列表让用户选择
CLPlacemark* placemark = placemarks[0];
CLLocation* location = placemark.location;
self.resultView.text = [NSString stringWithFormat:
@"%@的经度为:%g,纬度为:%g" , addr ,
location.coordinate.longitude ,
location.coordinate.latitude ];
}
// 没有得到解析结果。
else
{
// 使用UIAlertView提醒用户
[[[UIAlertView alloc] initWithTitle:@"提醒"
message:@"您输入的地址无法解析" delegate:nil
cancelButtonTitle:@"确定" otherButtonTitles: nil]
show];
}
}];
}
}
- (IBAction)reverseTapped:(id)sender
{
NSString* longitudeStr = self.longitudeField.text;
NSString* latitudeStr = self.latitudeField.text;
if(longitudeStr != nil && longitudeStr.length > 0
&& latitudeStr != nil && latitudeStr.length > 0)
{
// 将用户输入的经度、纬度封装成CLLocation对象
CLLocation* location = [[CLLocation alloc]
initWithLatitude:[latitudeStr floatValue]
longitude:[longitudeStr floatValue]];
[self.geocoder reverseGeocodeLocation:location completionHandler:
^(NSArray *placemarks, NSError *error)
{
// 如果解析结果的集合元素的个数大于1,表明解析得到了经度、纬度信息
if (placemarks.count > 0)
{
// 只处理第一个解析结果,实际项目可使用列表让用户选择
CLPlacemark* placemark = placemarks[0];
// 获取详细地址信息
NSArray* addrArray = [placemark.addressDictionary
objectForKey:@"FormattedAddressLines"];
// 将详细地址拼接成一个字符串
NSMutableString* addr = [[NSMutableString alloc] init];
for(int i = 0 ; i < addrArray.count ; i ++)
{
[addr appendString:addrArray[i]];
}
self.resultView.text = [NSString stringWithFormat:
@"经度:%g,纬度:%g的地址为:%@" ,
location.coordinate.longitude ,
location.coordinate.latitude , addr];
}
// 没有得到解析结果。
else
{
// 使用UIAlertView提醒用户
[[[UIAlertView alloc] initWithTitle:@"提醒"
message:@"您输入的地址无法解析" delegate:nil
cancelButtonTitle:@"确定" otherButtonTitles: nil]
show];
}
}];
}
}
iOS地址编码解析的更多相关文章
- iOS - JSON 数据解析
iOS - JSON 数据解析 前言 NS_CLASS_AVAILABLE(10_7, 5_0) @interface NSJSONSerialization : NSObject @availab ...
- iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像
iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像 本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImag ...
- iOS push全方位解析(二)【译文】"——生成OpenSSL证书,Provisioning Profile
这是一篇来自raywenderlich的教程,内容翔实!结构简单透彻.讲解循序渐进.文章质量上乘!是一篇难的的博文!使用半瓶的英语水平翻译了一下: 1.[iOS push全方位解析](一) push的 ...
- iOS开发 XML解析和下拉刷新,上拉加载更多
iOS开发 XML解析和下拉刷新,上拉加载更多 1.XML格式 <?xml version="1.0" encoding="utf-8" ?> 表示 ...
- 基于PHP的地址智能解析案例-快宝开放平台
快宝地址智能解析,批量录入收件人.发件人最好的解决方案,广泛应用于快递行业,电商行业,ERP应用等. 一.对接前准备 注册快宝开放平台,获得开发者账号,查看如何注册. 二.对接联调 快宝开放平台支持多 ...
- 【安全开发】IOS安全编码规范
申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...
- iOS使用TFHpple解析html
iOS 开发中解析html 网上有很多写好的解析框架 今天就来讲一下如何用框架TFHpple来解析html 使用TFHpple解析html github地址:https://github.com/to ...
- ios 表情编码
感受 :可以做自定义键盘时候用 很方便 还可以在textView里面看到 用户体验很好~ 但是要和服务器管理员协商好,做好解析转码工作,不然网页上是不显示的. ios表情编码 在ios中可以使用可爱 ...
- HTTP1.1中CHUNKED编码解析(转载)
HTTP1.1中CHUNKED编码解析 一般HTTP通信时,会使用Content-Length头信息性来通知用户代理(通常意义上是浏览器)服务器发送的文档内容长度,该头信息定义于HTTP1.0协议RF ...
随机推荐
- 6. redis持久化,认证
一. RDB 快照持久化 (默认) rdb机制,在满足redis.conf中配置的持久化策略后, 自动持久化数据, 默认存储在dump.rdb文件中 策略 : save 900 1 : 900秒内,一 ...
- EditPlus去行号/行标
正则表达式1: [0-9] ---------- > 1 2 3 正则表达式1: [0-9]+: ---------- > 1: 2: 3: 正 ...
- Sprite的原点
对于某些类型的游戏,例如飞行射击游戏或者顶视角的2D游戏,通常会直接选取图片的中心做为原点.但对于<冰杖秘闻>这样的 2D ARPG 来说,会更多的从三维场景的角度来选择原点,即选择物品底 ...
- 按钮/文本框 disabled
需求:已登入的,将用户的信息回填,用户文本框内容不能更改. 按钮: <button type="button" id="btnSearch">< ...
- DataTable中的数据赋值给model z
create table memberinfo ( member_id int, member_name varchar(20), member_birthday varchar(50) ) go / ...
- java中json包的使用以及字符串,map,list,自定义对象之间的相互转换
做一个map和字符串的转换,需要导入这些jar包,这是最基本的一些jar包. 经过多方尝试得出结论入下: 首先导入基本包:json-lib-2.2.3-jdk15.jar 如果没有这个jar包,程序是 ...
- Understanding Python metaclasses
转载:https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/ None of the existing article ...
- Prevent Adding Component More than once
Question: I'm developing a C# component, I want to prevent the user from adding this component to th ...
- Flex 医疗行程图
================================================ 病案的质量控制: 1.医生自检,主任检测,病案室检测达到三级检测 2.人工检测,自动检测 3.抽检(采 ...
- NEERC 2013, Eastern subregional contest
I. The old Padawan Time limit: 0.5 secondMemory limit: 64 MB Yoda: Use the Force. Yes. Now, the ston ...