高德地圖正/逆向地理編碼

應(yīng)該場景描述:后臺返回給我的地址,我需要將地址轉(zhuǎn)成 經(jīng)緯度拍冠,進行導(dǎo)航簇抵。
記錄原因:網(wǎng)上相關(guān)文檔正压,因為版本原因,更新不全面拓劝,無法快速實現(xiàn)功能

使用步驟:

  1. 項目中導(dǎo)入 高德地圖的 SDK 郑临,我用的是pod, 在pod文件中加入下面代碼,并執(zhí)行 pod install .
#高德地圖
    pod 'AMapSearch'
    pod 'AMapLocation'
    pod 'AMapNavi'
  1. 在需要使用的 XXX controller.h 導(dǎo)入頭文件
#import <AMapNaviKit/MAMapKit.h>    //  創(chuàng)建地圖需要
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
  1. XXX controller.m 中遵循 代理
@interface XXXMapController ()
<MAMapViewDelegate,
AMapSearchDelegate>
@end
  1. 功能代碼
- (void)viewDidLoad {
    [super viewDidLoad];
    // 隱藏navBar
    [self navBarNeedHidden:YES andAnimation:NO];
    
    [self configSubViews];
}

-(void)configSubViews {
    [AMapServices sharedServices].enableHTTPS = YES;
    // 配置用戶APP Key --> 自己在高德平臺去申請
    [[AMapServices sharedServices] setApiKey:@"xxxxxxxxxxxxxxxxxxx"];
    
    ///初始化地圖
    self.maMapView = [[MAMapView alloc] initWithFrame:self.mapBGView.bounds];
    self.maMapView.zoomLevel = 14.5f;
    self.search  = [[AMapSearchAPI alloc] init];
//    self.maMapView.delegate = self;
    self.search.delegate = self;
//發(fā)起正向地理編碼
    AMapGeocodeSearchRequest *searchRequest = [[AMapGeocodeSearchRequest alloc] init];
    // 將字符串的地址 通過正向地理編碼轉(zhuǎn)換為 經(jīng)緯度坐標(biāo)點
    searchRequest.address = self.addressStr;
    [self.search AMapGeocodeSearch: searchRequest];
// 發(fā)起逆向地理編碼
// AMapReGeocodeSearchRequest *searchRequest = [[AMapReGeocodeSearchRequest alloc] init];
    // searchRequest.location.latitude = xx.xxxxxx;
   // searchRequest.location.longitude = xx.xxxxxx;
   //  [self.search AMapReGoecodeSearch:searchRequest];
       ///把地圖添加至view
       [self.mapBGView addSubview:self.maMapView];
   
}


#pragma mark -- MAMapViewDelegate
// 自定義標(biāo)記點圖標(biāo)躺翻,暫時不需要自定義
/*
-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation {
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
       {
           static NSString *reuseIndetifier = @"annotationReuseIndetifier";
           MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
           if (annotationView == nil)
           {
               annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation
   reuseIdentifier:reuseIndetifier];
           }
           annotationView.image = [UIImage imageNamed:@"warehouseMap"];
           //設(shè)置中心點偏移公你,使得標(biāo)注底部中間點成為經(jīng)緯度對應(yīng)點
           annotationView.centerOffset = CGPointMake(0, -18);
           return annotationView;
       }
       return nil;
   
}
*/

#pragma mark -- AMapSearchDelegate
// 正向地理編碼(將文字地址轉(zhuǎn)換為坐標(biāo)點的經(jīng)緯度)
-(void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response {
    if (response.geocodes.count == 0) {

            return;
        }
    
    AMapGeoPoint *point = response.geocodes[0].location;
    self.latitude = point.latitude;
    self.longitude = point.longitude;
    self.maMapView.centerCoordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude);
    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(self.latitude, self.longitude);
    [self.maMapView addAnnotation:pointAnnotation];
    
}
// 逆向地理編碼(將文字地址轉(zhuǎn)換為坐標(biāo)點的經(jīng)緯度)
- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response

{

    if (![DDUtilsisNullOrNil:response.regeocode]) {

        AMapReGeocode *regeocode = response.regeocode;

        CLLocationDegrees latitude = request.location.latitude;

        CLLocationDegrees longitude = request.location.longitude;

        NSString *address = regeocode.formattedAddress; // 獲得檢索位置 

    } 

}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末迂尝,一起剝皮案震驚了整個濱河市剪芥,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌溉躲,老刑警劉巖寸认,帶你破解...
    沈念sama閱讀 216,692評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異唱蒸,居然都是意外死亡灸叼,警方通過查閱死者的電腦和手機古今,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,482評論 3 392
  • 文/潘曉璐 我一進店門捉腥,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人坏匪,你說我怎么就攤上這事撬统×底罚” “怎么了苦囱?”我有些...
    開封第一講書人閱讀 162,995評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長朽砰。 經(jīng)常有香客問我,道長喉刘,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,223評論 1 292
  • 正文 為了忘掉前任睦裳,我火速辦了婚禮,結(jié)果婚禮上廉邑,老公的妹妹穿的比我還像新娘。我一直安慰自己倒谷,他們只是感情好蛛蒙,可當(dāng)我...
    茶點故事閱讀 67,245評論 6 388
  • 文/花漫 我一把揭開白布渤愁。 她就那樣靜靜地躺著牵祟,像睡著了一般。 火紅的嫁衣襯著肌膚如雪抖格。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,208評論 1 299
  • 那天雹拄,我揣著相機與錄音,去河邊找鬼坪哄。 笑死,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的汰蓉。 我是一名探鬼主播,決...
    沈念sama閱讀 40,091評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼顾孽,長吁一口氣:“原來是場噩夢啊……” “哼若厚!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起蜒什,我...
    開封第一講書人閱讀 38,929評論 0 274
  • 序言:老撾萬榮一對情侶失蹤测秸,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后灾常,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體霎冯,經(jīng)...
    沈念sama閱讀 45,346評論 1 311
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,570評論 2 333
  • 正文 我和宋清朗相戀三年钞瀑,在試婚紗的時候發(fā)現(xiàn)自己被綠了沈撞。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,739評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡雕什,死狀恐怖缠俺,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情贷岸,我是刑警寧澤壹士,帶...
    沈念sama閱讀 35,437評論 5 344
  • 正文 年R本政府宣布,位于F島的核電站偿警,受9級特大地震影響躏救,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜螟蒸,卻給世界環(huán)境...
    茶點故事閱讀 41,037評論 3 326
  • 文/蒙蒙 一落剪、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧尿庐,春花似錦忠怖、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,677評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽枉疼。三九已至,卻和暖如春鞋拟,著一層夾襖步出監(jiān)牢的瞬間骂维,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,833評論 1 269
  • 我被黑心中介騙來泰國打工贺纲, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留航闺,地道東北人。 一個月前我還...
    沈念sama閱讀 47,760評論 2 369
  • 正文 我出身青樓猴誊,卻偏偏與公主長得像潦刃,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子懈叹,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,647評論 2 354

推薦閱讀更多精彩內(nèi)容