iOS 百度地圖SDK使用小結,ios地圖sdk小結

來源:互聯網
上載者:User

iOS 百度地圖SDK使用小結,ios地圖sdk小結

官方的整合介紹雖然很多,但是本人 用到的比較少,除了基本庫的匯入 和在AppDelegate離 regist外 其他用到的比較少,至少擷取當前地理位置的代碼 個人認為寫的不夠清除。


這裡主要介紹下如何開啟定位,反編碼地理座標 和城市雲搜尋。


BMKLocationServiceDelegate, BMKGeoCodeSearchDelegate


首頁匯入上面的代理方法

其次開啟百度定位服務

 [BMKLocationServicesetLocationDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];

    [BMKLocationServicesetLocationDistanceFilter:kCLLocationAccuracyBest];

    

    //初始化BMKLocationService

    _locService = [[BMKLocationServicealloc]init];

    _locService.delegate =self;

    //啟動LocationService

    [_locServicestartUserLocationService];

調用代理方法會擷取當前經緯度,獲得經緯後 使用搜尋 搜尋座標

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{


    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);

    // 建議擷取完經緯後停止位置更新  否則會一直更新座標

   if (userLocation.location.coordinate.latitude !=0) {

        [_locServicestopUserLocationService];

    }

    //調用搜尋

    BMKGeoCodeSearch *search = [[BMKGeoCodeSearchalloc]init];

    search.delegate =self;

    BMKReverseGeoCodeOption *rever = [[BMKReverseGeoCodeOptionalloc]init];

    rever.reverseGeoPoint = userLocation.location.coordinate;

    //這段代碼不要刪

   NSLog(@"%d",[searchreverseGeoCode:rever]);

}

搜尋代理方法裡就能返回具體地址了

#pragma mark GeoCodeResult 返回地理位置

-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error

{

   NSLog(@"%@",result.address);

}



以上就是擷取當前地理位置的代碼。



雲搜尋這塊我是在使用系統正常的SearchBar,在它的代理方法裡觸發雲搜尋 匯入代理

BMKGeoCodeSearchDelegate, BMKLocationServiceDelegate,BMKPoiSearchDelegate


- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

{

    //初始化poi搜尋

   _poiSearch = [[BMKPoiSearchalloc]init];

    _poiSearch.delegate =self;

    

    BMKCitySearchOption *option = [[BMKCitySearchOptionalloc]init];

    option.city =@"北京市";

    _searchTextFiled.placeholder =@"請輸入要切換的地址";

    option.keyword =_searchTextFiled.text;

   BOOL flag = [_poiSearchpoiSearchInCity:option];

   if(flag)

    {

//        NSLog(@"周邊檢索發送成功");

    }

   else

    {

//        NSLog(@"周邊檢索發送失敗");

    }


}

- (void)onGetPoiResult:(BMKPoiSearch*)searcher

                result:(BMKPoiResult*)poiResultList

             errorCode:(BMKSearchErrorCode)error

{

    if (error ==BMK_SEARCH_NO_ERROR) {

       //在此處理正常結果  poiResultList.totalPoiNum, poiResultList.poiInfoList 這兩個分別代表搜尋結果數量和存地址資訊的數組, forin 遍曆poiResultList.poiInfoList這個數組即可


        NSLog(@"%d %@", poiResultList.totalPoiNum, poiResultList.poiInfoList);

        NSArray *array = poiResultList.poiInfoList;

                

    }

    elseif (error ==BMK_SEARCH_AMBIGUOUS_KEYWORD){

        //當在設定城市未找到結果,但在其他城市找到結果時,回調建議檢索城市列表

        // result.cityList;

        NSLog(@"起始點有歧義");

    } else {

        NSLog(@"抱歉,未找到結果");

        

    }

}

以上為城市雲搜尋代碼,其他熱點搜尋等大家可以參考百度地圖開發人員中心裡的類參考 尋找即可。

如有疑問歡迎留言。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.