地圖-->地名VS地理坐標(biāo)(根據(jù)"北京"二字獲得北京市的坐標(biāo),區(qū)域等數(shù)據(jù))

地理編碼

除了提供位置跟蹤功能之外,在定位服務(wù)中還包含CLGeocoder類用于處理地理編碼和逆地理編碼(又叫反地理編碼)功能.
地理編碼:根據(jù)給定的位置(通常是地名)確定地理坐標(biāo)(經(jīng)、緯度).
逆地理編碼:可以根據(jù)地理坐標(biāo)(經(jīng)、緯度)確定位置信息(街道、門牌等).
CLGeocoder最主要的兩個(gè)方法就是- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;和- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler;,分別用于地理編碼和逆地理編碼。下面簡(jiǎn)單演示一下:

//
//  KCMainViewController.m
//  CoreLocation
//
//  Created by Kenshin Cui on 14-03-27.
//  Copyright (c) 2014年 Kenshin Cui. All rights reserved.
//

#import "KCMainViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface KCMainViewController ()<CLLocationManagerDelegate>{

    CLGeocoder *_geocoder;
}

@end

@implementation KCMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _geocoder=[[CLGeocoder alloc]init];
    [self getCoordinateByAddress:@"北京"];
    [self getAddressByLatitude:39.54 longitude:116.28];
}

#pragma mark 根據(jù)地名確定地理坐標(biāo)
-(void)getCoordinateByAddress:(NSString *)address{
    //地理編碼
    [_geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
        //取得第一個(gè)地標(biāo),地標(biāo)中存儲(chǔ)了詳細(xì)的地址信息,注意:一個(gè)地名可能搜索出多個(gè)地址
        CLPlacemark *placemark=[placemarks firstObject];
        
        CLLocation *location=placemark.location;//位置
        CLRegion *region=placemark.region;//區(qū)域
        NSDictionary *addressDic= placemark.addressDictionary;//詳細(xì)地址信息字典,包含以下部分信息
//        NSString *name=placemark.name;//地名
//        NSString *thoroughfare=placemark.thoroughfare;//街道
//        NSString *subThoroughfare=placemark.subThoroughfare; //街道相關(guān)信息,例如門牌等
//        NSString *locality=placemark.locality; // 城市
//        NSString *subLocality=placemark.subLocality; // 城市相關(guān)信息,例如標(biāo)志性建筑
//        NSString *administrativeArea=placemark.administrativeArea; // 州
//        NSString *subAdministrativeArea=placemark.subAdministrativeArea; //其他行政區(qū)域信息
//        NSString *postalCode=placemark.postalCode; //郵編
//        NSString *ISOcountryCode=placemark.ISOcountryCode; //國(guó)家編碼
//        NSString *country=placemark.country; //國(guó)家
//        NSString *inlandWater=placemark.inlandWater; //水源、湖泊
//        NSString *ocean=placemark.ocean; // 海洋
//        NSArray *areasOfInterest=placemark.areasOfInterest; //關(guān)聯(lián)的或利益相關(guān)的地標(biāo)
        NSLog(@"位置:%@,區(qū)域:%@,詳細(xì)信息:%@",location,region,addressDic);
    }];
}

#pragma mark 根據(jù)坐標(biāo)取得地名
-(void)getAddressByLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude{
    //反地理編碼
    CLLocation *location=[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
    [_geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark=[placemarks firstObject];
        NSLog(@"詳細(xì)信息:%@",placemark.addressDictionary);
    }];
}

@end
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • http://www.cnblogs.com/kenshincui/p/4125570.html 摘要: 現(xiàn)在很多...
    大崔老師閱讀 3,488評(píng)論 1 2
  • 出自http://my.oschina.net/are1OfBlog/blog/420034 摘要 現(xiàn)在很多社交、...
    JJO閱讀 4,339評(píng)論 4 19
  • 簡(jiǎn)介 在移動(dòng)互聯(lián)網(wǎng)時(shí)代,移動(dòng)app能解決用戶的很多生活瑣事,比如 周邊:找餐館、找KTV、找電影院等等 導(dǎo)航:根據(jù)...
    JonesCxy閱讀 1,547評(píng)論 1 1
  • 這是一條極美的路,青蔥的香樟與法國(guó)梧桐的相交映,從香樟開始,經(jīng)過法桐,再到路的盡頭,好似走了一個(gè)生命的過程。 從生...
    山有木希閱讀 665評(píng)論 6 12
  • 那一潭洶涌的真心實(shí)意, 在念念不忘中丟了執(zhí)著, 曾經(jīng)相融進(jìn)生命的風(fēng)景, 在人來(lái)人往中淡了視線, 捧起的流沙散落了,...
    蛋蛋妮兒閱讀 449評(píng)論 0 0

友情鏈接更多精彩內(nèi)容