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

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

code如下

#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.
//delegate
self.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(, , , );
[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.myGeocoder
reverseGeocodeLocation:self.location completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil &&[placemarks count] > ){
CLPlacemark *placemark = [placemarks objectAtIndex:];
/* 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] == ){
NSLog(@"No results were returned.");
}
else if (error != nil){
NSLog(@"An error occurred = %@", error);
}
}];
}
@end

输出如下:

  

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

[IOS地图开发系类]2、位置解码CLGeocoder的更多相关文章

  1. 【iOS地图开发】巧妙打造中英文全球地图

    地图开发的同学们经常遇到这样的问题,国内版地图开发,用高德或者百度就行了.但是,国外的地图怎么办?这里告诉大家,如果利用iOS地图,打造中英文的,国内国外都能用的,全球地图. 制作全英文地图的展示并不 ...

  2. android百度地图开发之自动定位所在位置与固定位置进行驾车,步行,公交路线搜索

    最近跟着百度地图API学地图开发,先是学了路径搜索,对于已知坐标的两点进行驾车.公交.步行三种路径的搜索(公交路径运行没效果,待学习中),后来又 学了定位功能,能够获取到自己所在位置的经纬度,但当将两 ...

  3. iOS开发----地图与导航--定位和位置信息获取

    要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...

  4. iOS原生地图开发指南续——大头针与自定义标注

    iOS原生地图开发指南续——大头针与自定义标注 出自:http://www.sxt.cn/info-6042-u-7372.html 在上一篇博客中http://my.oschina.net/u/23 ...

  5. iOS原生地图开发详解

    在上一篇博客中:http://my.oschina.net/u/2340880/blog/414760.对iOS中的定位服务进行了详细的介绍与参数说明,在开发中,地位服务往往与地图框架结合使用,这篇博 ...

  6. iOS原生地图开发进阶——使用导航和附近兴趣点检索

    iOS原生地图开发进阶——使用导航和附近兴趣点检索 iOS中的mapKit框架对国际化的支持非常出色.在前些篇博客中,对这个地图框架的基础用法和标注与覆盖物的添加进行了详细的介绍,这篇博客将介绍两个更 ...

  7. 【高德API】如何利用MapKit开发全英文检索的iOS地图

    原文:[高德API]如何利用MapKit开发全英文检索的iOS地图 制作全英文地图的展示并不困难,但是要制作全英文的数据检索列表,全英文的信息窗口,你就没办法了吧.告诉你,我有妙招!使用iOS自带的M ...

  8. iOS 原生地图 开发

    iOS开发有时候用到地图,不少人第一想到的是用第三方.当然有时候为了和安卓同步,可能会一起使用某一第三方.但有时候,我们是可以用原生地图开发的.上面两个示意图是原生地图的自定义开发.运行demo,将展 ...

  9. C#的百度地图开发(三)依据坐标获取位置、商圈及周边信息

    原文:C#的百度地图开发(三)依据坐标获取位置.商圈及周边信息 我们得到了百度坐标,现在依据这一坐标来获取相应的信息.下面是相应的代码 public class BaiduMap { /// < ...

随机推荐

  1. http://www.ruanyifeng.com/blog/2011/09/restful

    http://www.ruanyifeng.com/blog/2011/09/restful

  2. NEERC 2010, Eastern subregional contest

    只能把补了的题目放这儿了,先留个坑,怕忘记. Problem G URAL 1806 Mobile Telegraphs 题意是:给定n个电话号码,每个号码是一个长度为10的仅含'0'~'9'的字符串 ...

  3. asp.net 框架初接触

    1. 在web层的Default.aspx里只有最基本的UI代码 2. 在web层的Default.aspx.cs里第一行创建一个用户业务对象UserBO (注意添加引用,下同) protected ...

  4. 读写UTF-8、Unicode文件(加上了文件头,貌似挺好用)

    conf配置文件一些为UTF-8和Unicode格式,这样便可良好的支持多语言,从网上查阅资料后,将读写UTF-8.Unicode文件写了几个最精简的函数,更新后加了是否写文件头的功能,以适应更多需要 ...

  5. Google的代码风格规范,各种语言都很全

    https://code.google.com/p/google-styleguide/

  6. gdb 调试c/c++的一些小技巧

    ptype obj/class/struct 查看obj/class/struct的成员,但是会把基类指针指向的派生类识别为基类   set print object on 这个选项可以看到派生对象的 ...

  7. Emberjs View and Route

    index.html <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset=& ...

  8. URAL1658. Sum of Digits(DP)

    链接 这题卡了挺久了 昨天试着用类似dfs的方法直接TLE在第二组 看了下题解,,发现s1,s2的范围是个幌子..100位最大的s1900 s28100 觉得s1s2太大不敢开二维.. 这样就简单了 ...

  9. MySQL 内存监控

    上一篇blog介绍了因为sql查询information_schema表而导致内存暴涨的case. 今天顺便做了一个thd内存的监控: 先来介绍下MySQL的内存: 1. 线程内内存:thd-> ...

  10. 自动测试框架(by myself)

    这段日子以来一直在自动话测试,然后关于框架一直有个很模糊的概念,通过N多人的解说,这个应该不能算是一个框架,但是还是很模糊 如下图是我自己认为的框架,不知道是否正确(请大侠们多多指点) 1.用nuni ...