1. 程式人生 > >iOS使用百度地圖 獲取雲檢索資料

iOS使用百度地圖 獲取雲檢索資料

ARVR技術交流qq群602929993 ARVR訓練營:www.arvrthink.com

建立專案, Display Name與Bundle Identifier  與剛才建立AK時填寫的要一致

#import "AppDelegate.h"
#import <BaiduMapAPI_Map/BMKMapComponent.h>
@interface AppDelegate ()
@property (strong, nonatomic) BMKMapManager * mapManager;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _mapManager = [[BMKMapManager alloc]init];
    //使用iOS端的ak
    BOOL ret = [_mapManager start:@"lrlaVPD6IzjI65TRRon1qMaegyOjQddD" generalDelegate:nil];
    if(ret){
        NSLog(@"Manager start failed");
    }else{
       NSLog(@"Manager start");
    }
    // Override point for customization after application launch.
    return YES;
}

#import "ViewController.h"
#import <BaiduMapAPI_Cloud/BMKCloudSearch.h>//檢索
@interface ViewController ()<BMKCloudSearchDelegate>
@property (strong, nonatomic) BMKCloudSearch * search;

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];

    _search = [[BMKCloudSearch alloc]init];
    _search.delegate = self;
    
    [self startSearch];
    
    // Do any additional setup after loading the view, typically from a nib.
}


-(void)startSearch
{
    //周邊檢索
    BMKCloudNearbySearchInfo * cloudNearbySearch = [[BMKCloudNearbySearchInfo alloc]init];
    cloudNearbySearch.ak = @"bf0RbhE8DOsSBuyEDasmaPGGSURdnVke";//使用服務端的ak
    cloudNearbySearch.geoTableId = 174599;//填寫的id為資料庫表的id
    cloudNearbySearch.pageIndex = 0;
    cloudNearbySearch.pageSize = 10;
    cloudNearbySearch.location =  @"108.900255,34.163963";
    cloudNearbySearch.radius = 10000;
    cloudNearbySearch.keyword = @"5";
    
    BOOL flag = [_search nearbySearchWithSearchInfo:cloudNearbySearch];
    if (flag) {
        NSLog(@"周邊檢索傳送成功");
    }else{
        NSLog(@"周邊檢索傳送失敗");
    }
}

/**
 *返回雲檢索POI列表結果
 *@param poiResultList 雲檢索結果列表,成員型別為BMKCloudPOIList
 *@param type 返回結果型別: BMK_CLOUD_LOCAL_SEARCH,BMK_CLOUD_NEARBY_SEARCH,BMK_CLOUD_BOUND_SEARCH
 *@param error 錯誤號,@see BMKCloudErrorCode
 */
- (void)onGetCloudPoiResult:(NSArray*)poiResultList searchType:(int)type errorCode:(int)error
{
    BMKCloudPOIList * result = [poiResultList objectAtIndex:0];
    NSLog(@"Count %ld",result.POIs.count);
    for (int i = 0; i < result.POIs.count; i++) {
        BMKCloudPOIInfo *poi = [result.POIs objectAtIndex:i];
        NSLog(@"%@ weight:%f  distance:%f", poi.title,poi.weight,poi.distance);
       for(NSString * key in poi.customDict.allKeys)
         {
          NSLog(@"%@ : %@",key,poi.customDict[key]);
         }
    }
}

/**
 *返回雲檢索POI詳情
 *@param poiDetailResult 型別為BMKCloudPOIInfo
 *@param type 返回結果型別: BMK_CLOUD_DETAIL_SEARCH
 *@param error 錯誤號,@see BMKCloudErrorCode
 */
- (void)onGetCloudPoiDetailResult:(BMKCloudPOIInfo*)poiDetailResult searchType:(int)type errorCode:(int)error
{
    
}

/**
 *返回雲RGC檢索結果
 *@param cloudRGCResult 搜尋結果
 *@param type 返回結果型別: BMK_CLOUD_RGC_SEARCH
 *@param error 錯誤號,@see BMKCloudErrorCode
 */
- (void)onGetCloudReverseGeoCodeResult:(BMKCloudReverseGeoCodeResult*)cloudRGCResult searchType:(BMKCloudSearchType) type errorCode:(NSInteger) errorCode{
    
}

@end