- (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地址编码解析的更多相关文章

  1. iOS - JSON 数据解析

     iOS - JSON 数据解析 前言 NS_CLASS_AVAILABLE(10_7, 5_0) @interface NSJSONSerialization : NSObject @availab ...

  2. iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像

    iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像 本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImag ...

  3. iOS push全方位解析(二)【译文】"——生成OpenSSL证书,Provisioning Profile

    这是一篇来自raywenderlich的教程,内容翔实!结构简单透彻.讲解循序渐进.文章质量上乘!是一篇难的的博文!使用半瓶的英语水平翻译了一下: 1.[iOS push全方位解析](一) push的 ...

  4. iOS开发 XML解析和下拉刷新,上拉加载更多

    iOS开发 XML解析和下拉刷新,上拉加载更多 1.XML格式 <?xml version="1.0" encoding="utf-8" ?> 表示 ...

  5. 基于PHP的地址智能解析案例-快宝开放平台

    快宝地址智能解析,批量录入收件人.发件人最好的解决方案,广泛应用于快递行业,电商行业,ERP应用等. 一.对接前准备 注册快宝开放平台,获得开发者账号,查看如何注册. 二.对接联调 快宝开放平台支持多 ...

  6. 【安全开发】IOS安全编码规范

    申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...

  7. iOS使用TFHpple解析html

    iOS 开发中解析html 网上有很多写好的解析框架 今天就来讲一下如何用框架TFHpple来解析html 使用TFHpple解析html github地址:https://github.com/to ...

  8. ios 表情编码

    感受 :可以做自定义键盘时候用  很方便 还可以在textView里面看到 用户体验很好~ 但是要和服务器管理员协商好,做好解析转码工作,不然网页上是不显示的. ios表情编码 在ios中可以使用可爱 ...

  9. HTTP1.1中CHUNKED编码解析(转载)

    HTTP1.1中CHUNKED编码解析 一般HTTP通信时,会使用Content-Length头信息性来通知用户代理(通常意义上是浏览器)服务器发送的文档内容长度,该头信息定义于HTTP1.0协议RF ...

随机推荐

  1. Learning Core Data 1

    What is Core Data? If you want to build anything beyond the most simplistic apps for iOS, you’ll nee ...

  2. Kmeans算法学习与SparkMlLib Kmeans算法尝试

    K-means算法是最为经典的基于划分的聚类方法,是十大经典数据挖掘算法之一.K-means算法的基本思想是:以空间中k个点为中心进行聚类,对最靠近他们的对象归类.通过迭代的方法,逐次更新各聚类中心的 ...

  3. linux常用命令 3

    示例定义的 mytest或者test 用户 mygroup 用户组 cat /etc/group 查看组 groupname:x:groupId:其他成员 组名:x(加密):组ID:组成员cat /e ...

  4. Linux vmstat命令--监控CPU 性能分析

    top是给Linux设计的.在FreeBSD VM里面的Free概念和其他OS完全不同,使用top查看Free内存对于FreeBSD来说可以说没什么意义.正确的方法是看vmstat. vmstat是V ...

  5. Linux设置服务自启动(转载)

    From:http://www.cnblogs.com/nerxious/archive/2013/01/18/2866548.html 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统 ...

  6. c#生成缩略图

    publicstaticvoidGenThumbnail(Image imageFrom,stringpathImageTo,intwidth,intheight)         {         ...

  7. Liferay中actionURL能够执行后台方法 ,但是页面不跳转问题解决方案

    在学习liferay的过程中,遇到了这么一个问题,actionURL能够执行后台方法 ,但是页面不跳转,以下是两种解决方案: 方案1(不推荐此种办法): 强制将页面重定向. 在actionURL执行的 ...

  8. IDEA Community(社区版) 使用Maven创建Web工程 并部署tomcat

    由于IDEA社区版(Community)无法直接New一个Web Appplication 所以要使用maven来创建 1.创建一个Project 2. 3. 4.这里在Properties中添加一个 ...

  9. Run Configuration error:broken configuration due to unavailable

    希望大家一起来,毕竟大家都不会使用这个Androidstudio,一起扩展这方面的知识量 http://forums.opengamma.com/t/intellij-code-compiles-bu ...

  10. Android中对日期进行排序

    最近在项目中需要将读取的数据按照时间的降序进行排序. 具体的步骤如下: 1.读取数据,存入List中 2.取出数据中的时间戳,由String转换成Date 3.使用冒泡排序对List中元素按照Date ...