百度地圖集成

百度地圖

百度地圖開放平臺

  • 獲取秘鑰
  • 配置開發(fā)環(huán)境
    使用cocoapods自動配置
    pod 'BaiduMapKit' #百度地圖SDK
  • 注意事項
  • HelloBaiduMap

基礎地圖

#pragma mark - 基礎地圖常用功能
//設置地圖類型
    _mapView.mapType = BMKMapTypeNone;//設置地圖為空白類型
    
    //切換為衛(wèi)星圖
    [_mapView setMapType:BMKMapTypeSatellite];
    
    //切換為普通地圖
    [_mapView setMapType:BMKMapTypeStandard];
    
    //打開實時路況圖層
    [_mapView setTrafficEnabled:YES];
    
    //打開百度城市熱力圖圖層(百度自有數(shù)據(jù))
    [_mapView setBaiduHeatMapEnabled:YES];
    
    //關閉百度城市熱力圖圖層(百度自有數(shù)據(jù))
    [_mapView setBaiduHeatMapEnabled:NO];
    
    //logo位置
    _mapView.logoPosition = BMKLogoPositionCenterTop;
    
    // 添加一個PointAnnotation
    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor;
    coor.latitude = 39.915;
    coor.longitude = 116.404;
    annotation.coordinate = coor;
    annotation.title = @"這里是北京";
    [_mapView addAnnotation:annotation];
#pragma mark - 動畫效果
// Override
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
        newAnnotationView.animatesDrop = YES;// 設置該標注點動畫顯示
        return newAnnotationView;
    }
    return nil;
}

室內(nèi)地圖

//打開室內(nèi)圖
    _mapView.baseIndoorMapEnabled = YES;
//設置地圖大小
_mapView.zoomLevel = 15;

POI檢索

POI檢索,需要在鑒權之后

BMKPoiSearch *_searcher;
//---------------------------------------------------------------
//延遲檢索
[self performSelector:@selector(searchPOI) withObject:nil afterDelay:2.0];
//---------------------------------------------------------------
-(void)searchPOI {
    //初始化檢索對象
    _searcher =[[BMKPoiSearch alloc]init];
    _searcher.delegate = self;
    //發(fā)起檢索
    BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc]init];
    option.pageIndex = 0;
    option.pageCapacity = 10;
    option.location = CLLocationCoordinate2DMake(39.915, 116.404);
    option.keyword = @"小吃";
    BOOL flag = [_searcher poiSearchNearBy:option];
    
    if(flag)
    {
        NSLog(@"周邊檢索發(fā)送成功");
    }
    else
    {
        NSLog(@"周邊檢索發(fā)送失敗");
    }

}
#pragma mark - BMKPoiSearchDelegate
//實現(xiàn)PoiSearchDeleage處理回調(diào)結果
- (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResultList errorCode:(BMKSearchErrorCode)error
{
    if (error == BMK_SEARCH_NO_ERROR) {
        //在此處理正常結果
        for (BMKPoiInfo *poiInfo in poiResultList.poiInfoList) {
            // 添加一個PointAnnotation
            BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
            annotation.coordinate = poiInfo.pt;
            annotation.title = poiInfo.name;
            [_mapView addAnnotation:annotation];
        }
    }
    else if (error == BMK_SEARCH_AMBIGUOUS_KEYWORD){
        //當在設置城市未找到結果,但在其他城市找到結果時,回調(diào)建議檢索城市列表
        // result.cityList;
        NSLog(@"起始點有歧義");
    } else {
        NSLog(@"抱歉,未找到結果");
        NSLog(@"%d",error);
    }
}
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

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