//
// ViewController.m
// 逆编码地理
//
// Created by administrator on 15/8/27.
// Copyright (c) 2015年 gengcong. All rights reserved.
//
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<CLLocationManagerDelegate>
{
CLLocationManager *_locationmanger;
CLGeocoder *_geocoder;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_locationmanger =[[CLLocationManager alloc]init];
_geocoder=[[CLGeocoder alloc]init];
[self getAddressByLatitude:31.2825570000 longitude:120.7477660000];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark 根据坐标取得地名
//纬度latitude
//经度longitude
//反地理编码
-(void)getAddressByLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude
{
CLLocation *location=[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
//下面的block块是一个异步的闭包,不一定会先执行完,但是执行完之后他会返回的
[_geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark=[placemarks firstObject];
NSDictionary *addressdict=placemark.addressDictionary;
NSLog(@"详细信息%@",addressdict);
NSString *name=placemark.name;
//地名
NSString *thoroughfare=placemark.thoroughfare;//街道
NSString *subThoroughfare=placemark.subThoroughfare; //街道相关信息,例如门牌等
NSString *locality=placemark.locality; // 城市
NSString *subLocality=placemark.subLocality; // 城市相关信息,例如标志性建筑
NSString *administrativeArea=placemark.administrativeArea; // 州
NSString *subAdministrativeArea=placemark.subAdministrativeArea; //其他行政区域信息
NSString *postalCode=placemark.postalCode; //邮编
NSString *ISOcountryCode=placemark.ISOcountryCode; //国家编码
NSString *country=placemark.country; //国家
NSString *inlandWater=placemark.inlandWater; //水源、湖泊
NSString *ocean=placemark.ocean; // 海洋
NSArray *areasOfInterest=placemark.areasOfInterest; //关联的或利益相关的地标
NSLog(@"%@%@%@%@%@%@%@%@%@%@%@%@%@",name,thoroughfare,subThoroughfare,locality,subLocality,administrativeArea,subAdministrativeArea,postalCode,ISOcountryCode,country,inlandWater,ocean,areasOfInterest);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
逆地理编码(根据经纬度找到地名)
最新推荐文章于 2024-01-17 21:02:29 发布