第一步的操作,获取到地址信息经纬度后,我们可以对其进行解码,解码采用的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 = 西直门外大街

最新文章

  1. javascript,从库到框架再到平台
  2. java自带线程池和队列详细讲解
  3. 动态规划(DP),模拟
  4. php中一个&quot;异类&quot;语法: $a &amp;&amp; $b = $c;
  5. 【代码】ini 文件读取工具类
  6. Javascript三元条件运算符
  7. [App]Android Studio First App
  8. 你好,C++(12)怎样管理多个类型同样性质同样的数据?3.6 数组
  9. HUD 2089 位数dp
  10. iOS_block内存分析
  11. 在ubuntu安装Phabricator(转)
  12. N个骰子的点数和的概率分布
  13. 使用hexdump工具追踪EXT4文件系统中的一个文件
  14. chrome开发工具指南(十三)
  15. Nginx 简单记录
  16. Android应用跳转到微信和支付宝扫一扫
  17. vs 修改活动解决方案配置后无法调试,不生成pdb文件,“当前不会命中断点 还没有为该文档加载任何符号” 解决方法
  18. 安装Oracle Grid的过程中用到的几个小技巧
  19. vue中子组件通过$parent操作父组件的参数或者方法
  20. C_数据结构_数组的修改和删除

热门文章

  1. codeforces 391C3 - The Tournament
  2. StreamCQL
  3. [杂题]URAL1822. Hugo II&#39;s War
  4. Android 使用 popupWindow实现弹层并操作弹层元素
  5. 【HDOJ】2086 A1 = ?
  6. bzoj2749
  7. C#如何获取真实IP地址
  8. 使用PowerShell脚本部署定时器到MOSS2010
  9. c# 模拟http post 带cookie
  10. HDU 2817 A sequence of numbers