逆地理编码(根据经纬度找到地名)

//
//  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











  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值