[IOS地图开发系类]2、位置解码CLGeocoder

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

 接第一步的操作,获取到地址信息经纬度后,我们可以对其进行解码,解码采用的CLGeocoder这个类,使用方式如下:

1、在ViewControlelr.m文件中声明一个CLGeocoder的属性,给页面加一个button,然后在处理方法中,对上一篇获取的地址坐标进行解码,

code如下:

//
//  ViewController.m
//  LBS_001_CLLocationManager
//
//  Created by liqun on 13-7-17.
//  Copyright (c) 2013年 Block Cheng. All rights reserved.
//#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface ViewController ()<CLLocationManagerDelegate,MKMapViewDelegate>{
}
@property (nonatomic,retain)CLLocationManager* locationManager;
@property (nonatomic,retain)CLLocation* location;
@property (nonatomic, retain) CLGeocoder *myGeocoder;
@end@implementation ViewController-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {_locationManager = [[CLLocationManager alloc] init];}return  self;
}
- (void)dealloc
{self.locationManager = nil;self.location = nil;self.myGeocoder = nil;[super dealloc];
}
- (void)viewDidLoad
{[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.//delegateself.locationManager.delegate = self;//The desired location accuracy. self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;//Specifies the minimum update distance in meters.self.locationManager.distanceFilter = kCLDistanceFilterNone;self.locationManager.purpose =@"To provide functionality based on user's current location.";[self.locationManager startUpdatingLocation];UIButton *addBt = [UIButton buttonWithType:UIButtonTypeRoundedRect];addBt.frame = CGRectMake(0, 00, 320, 50);[addBt setTitle:@"locationMe" forState:UIControlStateNormal];[addBt addTarget:self action:@selector(handleLocationMe:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:addBt];self.myGeocoder = [[CLGeocoder alloc] init];
}- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{NSLog(@"didChangeAuthorizationStatus---%u",status);
}- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{NSLog(@"didChangeAuthorizationStatus----%@",error);
}- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"update" message:[NSString stringWithFormat:@"didUpdateToLocation:  newLocation: %@  old:%@",newLocation,oldLocation] delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];[av show];[av release];self.location = newLocation;NSLog(@"didUpdateToLocation:  newLocation: %@",newLocation);
}- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}-(IBAction)handleLocationMe:(id)sender
{[self.myGeocoderreverseGeocodeLocation:self.location completionHandler:^(NSArray *placemarks, NSError *error) {if (error == nil &&[placemarks count] > 0){CLPlacemark *placemark = [placemarks objectAtIndex:0];/* We received the results */NSLog(@"Country = %@", placemark.country);NSLog(@"Postal Code = %@", placemark.postalCode);NSLog(@"Locality = %@", placemark.locality);NSLog(@"dic = %@", placemark.addressDictionary );NSLog(@"dic FormattedAddressLines= %@", [placemark.addressDictionary objectForKey:@"FormattedAddressLines"]);NSLog(@"dic Name = %@", [placemark.addressDictionary objectForKey:@"Name"]);NSLog(@"dic State = %@", [placemark.addressDictionary objectForKey:@"State"]);NSLog(@"dic Street = %@", [placemark.addressDictionary objectForKey:@"Street"]);NSLog(@"dic SubLocality= %@", [placemark.addressDictionary objectForKey:@"SubLocality"]);NSLog(@"dic SubThoroughfare= %@", [placemark.addressDictionary objectForKey:@"SubThoroughfare"]);NSLog(@"dic Thoroughfare = %@", [placemark.addressDictionary objectForKey:@"Thoroughfare"]);}else if (error == nil &&[placemarks count] == 0){NSLog(@"No results were returned.");}else if (error != nil){NSLog(@"An error occurred = %@", error);}}];
}
@end
日志输出如下:

2013-07-28 20:47:16.578 LBS_001_CLLocationManager[30123:907] didChangeAuthorizationStatus---3
2013-07-28 20:47:17.288 LBS_001_CLLocationManager[30123:907] didUpdateToLocation:  newLocation: <+39.93751238,+116.34143052> +/- 65.00m (speed -1.00 mps / course -1.00) @ 13-7-28 中国标准时间下午8时47分16秒
2013-07-28 20:47:17.300 LBS_001_CLLocationManager[30123:907] didUpdateToLocation:  newLocation: <+39.93751238,+116.34143052> +/- 65.00m (speed -1.00 mps / course -1.00) @ 13-7-28 中国标准时间下午8时47分16秒
2013-07-28 20:47:17.351 LBS_001_CLLocationManager[30123:907] didUpdateToLocation:  newLocation: <+39.93770077,+116.34199932> +/- 70.88m (speed -1.00 mps / course -1.00) @ 13-7-28 中国标准时间下午8时47分16秒
2013-07-28 20:47:17.392 LBS_001_CLLocationManager[30123:907] didUpdateToLocation:  newLocation: <+39.93767287,+116.34189085> +/- 65.00m (speed -1.00 mps / course -1.00) @ 13-7-28 中国标准时间下午8时47分17秒
2013-07-28 20:47:51.976 LBS_001_CLLocationManager[30123:907] Country = 中国
2013-07-28 20:47:51.977 LBS_001_CLLocationManager[30123:907] Postal Code = (null)
2013-07-28 20:47:51.979 LBS_001_CLLocationManager[30123:907] Locality = (null)
2013-07-28 20:47:51.980 LBS_001_CLLocationManager[30123:907] dic = {Country = "\U4e2d\U56fd";CountryCode = CN;FormattedAddressLines =     ("\U4e2d\U56fd\U5317\U4eac\U5e02\U897f\U57ce\U533a\U5c55\U89c8\U8def\U8857\U9053\U897f\U76f4\U95e8\U5916\U5927\U8857132\U53f7");Name = "\U4e2d\U56fd\U5317\U4eac\U5e02\U897f\U57ce\U533a\U5c55\U89c8\U8def\U8857\U9053\U897f\U76f4\U95e8\U5916\U5927\U8857132\U53f7";State = "\U5317\U4eac\U5e02";Street = "\U897f\U76f4\U95e8\U5916\U5927\U8857 132\U53f7";SubLocality = "\U897f\U57ce\U533a";SubThoroughfare = "132\U53f7";Thoroughfare = "\U897f\U76f4\U95e8\U5916\U5927\U8857";
}
2013-07-28 20:47:51.982 LBS_001_CLLocationManager[30123:907] dic FormattedAddressLines= ("\U4e2d\U56fd\U5317\U4eac\U5e02\U897f\U57ce\U533a\U5c55\U89c8\U8def\U8857\U9053\U897f\U76f4\U95e8\U5916\U5927\U8857132\U53f7"
)
2013-07-28 20:47:51.983 LBS_001_CLLocationManager[30123:907] dic Name = 中国北京市西城区展览路街道西直门外大街132号
2013-07-28 20:47:51.985 LBS_001_CLLocationManager[30123:907] dic State = 北京市
2013-07-28 20:47:51.986 LBS_001_CLLocationManager[30123:907] dic Street = 西直门外大街 132号
2013-07-28 20:47:51.987 LBS_001_CLLocationManager[30123:907] dic SubLocality= 西城区
2013-07-28 20:47:51.988 LBS_001_CLLocationManager[30123:907] dic SubThoroughfare= 132号
2013-07-28 20:47:51.989 LBS_001_CLLocationManager[30123:907] dic Thoroughfare = 西直门外大街


转载于:https://my.oschina.net/chengliqun/blog/147871

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/301084.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

微软相关的开发资源列表(update)

MSDN总站 http://www.msdn.com/MSDN中文站 http://www.microsoft.com/china/msdn/MSDN台湾站http://www.microsoft.com/taiwan/ASP.NET总站 http://www.asp.net/http://www.gotdotnet.com/SQLServerCentral.com is the largest free SQL Server community on the Internet. W…

备战数学建模国赛,快速搞定算法模型!

全世界只有3.14 % 的人关注了青少年数学之旅说到数学建模&#xff0c;大家的第一反应就是国赛、美赛等数学建模比赛&#xff0c;但这只是冰山一角&#xff0c;不过这个反应却也很正常&#xff0c;因为很多小伙伴接触数学建模的契机&#xff0c;大部分还是因为数学建模相关的竞赛…

考虑用Task.WhenAll

异步能在一定场景中带性能的飞跃&#xff0c;同步调用性能&#xff0c;也以带来时间的节省。先看一下被调用的api:using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Th…

wordpress home.php,WordPress主题通过function.php来加载js和css文件

WordPress主题开发的时候可以直接将需要的js或css写在head标签中&#xff0c;但是现在已经不主张这种加载方式了&#xff0c;现在WordPress主题通过function.php来加载js和css文件。基本架构//加载css及jsfunction wpdie_add_scripts() {wp_enqueue_style(style, get_template_…

国际数学大师评丘成桐:在哈佛,一人就是一个数学系

全世界只有3.14 %的人关注了青少年数学之旅丘成桐教授与蕉岭县乡亲们亲切交谈国际数学大师、阿贝尔奖获得者辛格评价丘成桐&#xff1a;“即使在哈佛&#xff0c;一个人就是一个数学系”《数学界的国王》是美国《纽约时报》刊登丘成桐人物报道的标题&#xff0c;此报道更是《纽…

你的密码已泄露!使用C#阻止弱密码

虽然&#xff0c;我们为了安全考虑&#xff0c;在注册用户时会检查密码规则&#xff0c;避免弱密码&#xff0c;比如百度的注册页面&#xff1a; 但是&#xff0c;现在的黑客也不会傻到用穷举的办法生成密码去攻击网站&#xff0c;更常用的方式是使用已泄露密码生成的字典。那这…

SVN的VS.NET插件——AnkhSVN

用了几个月SubVersionTortoiseSVN&#xff0c;感觉很不错。唯一美中不足的就是TortoiseSVN是在WINDOWS资源管理中进行操作的&#xff0c;在实际开发中&#xff0c;项目中新建了个文件&#xff0c;经常会忘记了将文件加入SVN管理。这样在下次提交时这个文件就不会被提交&#xf…

中国人数学好,数学思维差?

小天经常可以看到在微博热搜吐槽歪果仁数学不好的段子&#xff0c;比如6.8&#xff0c;我们习惯给11.8&#xff0c;让收银员找5块钱&#xff0c;但歪果仁就不行啦&#xff0c;这样他们会更乱&#xff01;所以我们容易觉得中国人数学好&#xff0c;算数特别快还准&#xff01;但…

生产力提升! 自己动手自定义Visual Studio 2019的 类创建模板,制作简易版Vsix安装包...

序言最近一直在开发 webApi 接口&#xff0c;为了方便我采用了反Restful风格开发&#xff0c;90%的接口均采用post方式&#xff0c;小部分查询采用Get方式&#xff0c;接口的入参和出参定义每次都需要手动创建2个类&#xff0c;心不累手累&#xff0c;怎么能减轻点工作&#xf…

【个人笔记】关于IO类中流的整理

学习IO部分的知识后&#xff0c;被处理流的各种类搞得有点乱&#xff0c;所以得写篇文章总结下。IO包里面有很多输入输出类&#xff0c;一般我们是通过控制流来控制输入输出的。IO包里面对于控制流分为两大类&#xff0c;一类是字节流&#xff0c;一类是字符流。字符流的两个大…

全国胸最小的省是哪个,你知道吗?| 今日最佳

全世界只有3.14 % 的人关注了青少年数学之旅&#xff08;图源网络&#xff0c;侵权删&#xff09;所以最大的是哪个省的↓ ↓ ↓

.NET Core with 微服务 - Elastic APM

上一次我们介绍了Seq日志聚合组件。这次要给大家介绍的是Elastic APM &#xff0c;一款应用程序性能监控组件。APM 监控围绕对应用、服务、容器的健康监控&#xff0c;对接口的调用链、性能进行监控。在我们实施微服务后&#xff0c;由于复杂的业务逻辑&#xff0c;服务之间的调…

java 推送数据给js,Node.js实现数据推送

场景&#xff1a;后端更新数据推送到客户端(Java部分使用Tomcat服务器)。后端推送数据的解决方案有很多&#xff0c;比如轮询、Comet、WebSocket。1. 轮询对于后端来说开发成本最低&#xff0c;就是按照传统的方式处理Ajax请求并返回数据&#xff0c;在学校的时候实验室的项目一…

【开学季限时免费】下载19880元大数据开发全链路教程(视频+源码)

随着大数据、云计算、物联网、人工智能这些行业的发展崛起&#xff0c;对于大数据人才的需求越来越大&#xff0c;而大数据人才的培养发展周期相对较长&#xff0c;导致了大数据人才短缺&#xff0c;市场供不应求。所以也就出现了大数据开发工程师、数仓工程师、ETL工程师.....…

COM 组件设计与应用(七)

COM 组件设计与应用&#xff08;七&#xff09;编译、注册、调用作者&#xff1a;杨老师 一、前言  上两回中&#xff0c;咱们用 ATL 写了第一个 COM 组件程序&#xff0c;这回中&#xff0c;主要介绍编译、注册和调用方法。示例程序你已经下载了吗&#xff1f;如果还没有下载…

人类史上20个“最强大脑”

全世界只有3.14 %的人关注了青少年数学之旅今天给大家说道说道这人类历史上20位最强大脑&#xff0c;这些伟人来自各个不同的时期和领域&#xff0c;他们的思想和贡献对人类日后有着重大的影响&#xff0c;其中包括了众多的科学家&#xff0c;哲学家&#xff0c;诗人&#xff0…

LYNC2013部署系列PART4:群聊部署

前言&#xff1a;本篇文章将介绍LYNC2013群聊服务器的部署&#xff0c;在LYNC2010中&#xff0c;群聊服务还没集成到LYNC2010产品中&#xff0c;需要单独额外部署&#xff0c;群聊客户端也没有集成到LYNC2010客户端中。到LYNC2013中&#xff0c;集成工作全部搞定了。我是习惯了…

不要笑!写 | 还是 || ,还真是一个问题

这么简单的问题还写&#xff1f;先不要笑。打开你代码量最多的项目&#xff0c;搜索|或者&,看看有多少条这样的代码&#xff01;前不久&#xff0c;我在dotnet/machinelearning上提交了一个pull request。修改内容是把"|"改成"||", 把"&"…

UNIX网络编程——ioctl 函数的用法详解

1.介绍Linux网络程序与内核交互的方法是通过ioctl来实现的&#xff0c;ioctl与网络协议栈进行交互&#xff0c;可得到网络接口的信息&#xff0c;网卡设备的映射属性和配置网络接口。并且还能够查看&#xff0c;修改&#xff0c;删除ARP高速缓存的信息&#xff0c;所以&#xf…

你对求生欲,一无所知!| 今日最佳

全世界只有3.14 % 的人关注了青少年数学之旅【1】【2】【3】【4】【5】【6】【7】【8】【9】【10】【11】【12】【13】【14】【15】&#xff08;图源网络&#xff0c;侵权删&#xff09;学到了吗&#xff1f;↓ ↓ ↓