iOS 高德地圖的簡(jiǎn)單使用心得

定位 搜索 附近相關(guān)信息

  • pod AMap2DMap
  • pod AMapSeaerch
  • pod AMapLocation
#import <MAMapKit/MAMapKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
#import <AMapLocationKit/AMapLocationKit.h>
@interface ViewController ()<MAMapViewDelegate,AMapSearchDelegate>
{
    MAMapView * _mapView;
    AMapSearchAPI * _search;
    AMapLocationManager * _locationManager;
    NSString * _position;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self searchPosition];
    [self creatAmapView];
    [self getCurrentPositionInfo];
}
#pragma  mark -------------------根據(jù)經(jīng)緯度搜索周圍信息-------------------------
-(void)searchPosition{
    
    //搜索地址獲得地址附近信息
    [AMapSearchServices sharedServices].apiKey = @"你申請(qǐng)的key";
    _search = [[AMapSearchAPI alloc] init];
    _search.delegate = self;
    [self ahah];
    
}

-(void)ahah{
    
    AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init];
    request.location = [AMapGeoPoint locationWithLatitude:26.063184 longitude:119.298224];
    request.keywords = _position;
    // types屬性表示限定搜索POI的類別肃拜,默認(rèn)為:餐飲服務(wù)|商務(wù)住宅|生活服務(wù)
    // POI的類型共分為20種大類別该园,分別為:
    // 汽車服務(wù)|汽車銷售|汽車維修|摩托車服務(wù)|餐飲服務(wù)|購(gòu)物服務(wù)|生活服務(wù)|體育休閑服務(wù)|
    // 醫(yī)療保健服務(wù)|住宿服務(wù)|風(fēng)景名勝|(zhì)商務(wù)住宅|政府機(jī)構(gòu)及社會(huì)團(tuán)體|科教文化服務(wù)|
    // 交通設(shè)施服務(wù)|金融保險(xiǎn)服務(wù)|公司企業(yè)|道路附屬設(shè)施|地名地址信息|公共設(shè)施
    request.types = @"餐飲服務(wù)|生活服務(wù)|商務(wù)住宅";
    request.sortrule = 0;
    request.radius = 700;
    request.requireExtension = YES;
    
    //發(fā)起周邊搜索
    [_search AMapPOIAroundSearch: request];
}
//實(shí)現(xiàn)POI搜索對(duì)應(yīng)的回調(diào)函數(shù)
- (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response
{
    if(response.pois.count == 0)
    {
        return;
    }
    
    //通過 AMapPOISearchResponse 對(duì)象處理搜索結(jié)果
    //NSString *strCount = [NSString stringWithFormat:@"count: %ld",response.count];
    //NSString *strSuggestion = [NSString stringWithFormat:@"Suggestion: %@", response.suggestion];
    NSString *strPoi = @"";
    for (AMapPOI *p in response.pois) {
        strPoi = [NSString stringWithFormat:@"%@\nPOI: %@", strPoi, p.description];
        NSLog(@"%@*%@*%@",p.description,p.name,p.address);
    }
}
#pragma mark ------------------------地圖的創(chuàng)建---------------------------
-(void)creatAmapView{
    
    //地圖
    [MAMapServices sharedServices].apiKey = @"你申請(qǐng)的key";
    _mapView = [[MAMapView alloc] initWithFrame:self.view.frame];
    _mapView.showsUserLocation = YES;
    [_mapView setZoomLevel:16.1 animated:YES];
    _mapView.delegate = self;
    _mapView.userTrackingMode = MAUserTrackingModeFollow;
    [self.view addSubview:_mapView];
    
}

-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation
updatingLocation:(BOOL)updatingLocation
{
    if(updatingLocation)
    {
        //取出當(dāng)前位置的坐標(biāo)
        //NSLog(@"latitude : %f,longitude: %f",userLocation.coordinate.latitude,userLocation.coordinate.longitude);
    }
}
#pragma mark -----------------獲得當(dāng)前位置信息城市 區(qū) 街道-------------------------


-(void)getCurrentPositionInfo{
    [AMapLocationServices sharedServices].apiKey = @"你申請(qǐng)的key";
    _locationManager = [[AMapLocationManager alloc] init];
    [_locationManager setDistanceFilter:kCLLocationAccuracyKilometer];
    [self getCurrentAddress];
 }
//獲取當(dāng)前位置信息
-(void)getCurrentAddress{
    
    [_locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
        
        if (error) {
            NSLog(@"獲取當(dāng)前地址錯(cuò)誤");
            return;
        }
        NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
        [addressDic setValue:regeocode.province forKey:@"province"];
//        [addressDic setValue:regeocode.city forKey:@"city"];
//        [addressDic setValue:regeocode.district forKey:@"district"];
        NSString * position = [NSString stringWithFormat:@"%@%@%@%@",regeocode.city,regeocode.district,regeocode.street,regeocode.number];
        _position = position;
      
//city 市 district 區(qū) street 街道 number  街道號(hào)碼 
       NSLog(@"%@%@%@%@",regeocode.city,regeocode.district,regeocode.street,regeocode.number);
     }];
    
}
#pragma mark --------點(diǎn)擊地圖得到點(diǎn)擊點(diǎn)的坐標(biāo)------------------


//點(diǎn)擊地圖獲得該點(diǎn)擊地點(diǎn)的經(jīng)緯度
-(void)mapView:(MAMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate{

    NSLog(@"%f,%f",coordinate.latitude,coordinate.longitude);


}```
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末敛劝,一起剝皮案震驚了整個(gè)濱河市羔沙,隨后出現(xiàn)的幾起案子罗晕,更是在濱河造成了極大的恐慌,老刑警劉巖洼哎,帶你破解...
    沈念sama閱讀 218,941評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件呕屎,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡趴梢,警方通過查閱死者的電腦和手機(jī)漠畜,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,397評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來坞靶,“玉大人憔狞,你說我怎么就攤上這事≌靡酰” “怎么了瘾敢?”我有些...
    開封第一講書人閱讀 165,345評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)尿这。 經(jīng)常有香客問我簇抵,道長(zhǎng),這世上最難降的妖魔是什么射众? 我笑而不...
    開封第一講書人閱讀 58,851評(píng)論 1 295
  • 正文 為了忘掉前任碟摆,我火速辦了婚禮,結(jié)果婚禮上叨橱,老公的妹妹穿的比我還像新娘典蜕。我一直安慰自己,他們只是感情好罗洗,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,868評(píng)論 6 392
  • 文/花漫 我一把揭開白布嘉裤。 她就那樣靜靜地躺著,像睡著了一般栖博。 火紅的嫁衣襯著肌膚如雪屑宠。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,688評(píng)論 1 305
  • 那天仇让,我揣著相機(jī)與錄音典奉,去河邊找鬼。 笑死丧叽,一個(gè)胖子當(dāng)著我的面吹牛卫玖,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播踊淳,決...
    沈念sama閱讀 40,414評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼假瞬,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼陕靠!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起脱茉,我...
    開封第一講書人閱讀 39,319評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤剪芥,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后琴许,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體税肪,經(jīng)...
    沈念sama閱讀 45,775評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評(píng)論 3 336
  • 正文 我和宋清朗相戀三年榜田,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了益兄。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,096評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡箭券,死狀恐怖净捅,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情辩块,我是刑警寧澤灸叼,帶...
    沈念sama閱讀 35,789評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站庆捺,受9級(jí)特大地震影響古今,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,437評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望贞滨。 院中可真熱鬧瑰枫,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,993評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽拟逮。三九已至,卻和暖如春适滓,著一層夾襖步出監(jiān)牢的瞬間敦迄,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,107評(píng)論 1 271
  • 我被黑心中介騙來泰國(guó)打工凭迹, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留罚屋,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,308評(píng)論 3 372
  • 正文 我出身青樓嗅绸,卻偏偏與公主長(zhǎng)得像脾猛,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子鱼鸠,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,037評(píng)論 2 355

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