iOS百度地圖SDK整合詳細步驟,iossdk整合詳細步驟

來源:互聯網
上載者:User

iOS百度地圖SDK整合詳細步驟,iossdk整合詳細步驟

1.iOS百度地圖 http://developer.baidu.com/map/index.php?title=iossdk/sdkiosdev-download

根據需要選擇不同的版本  這裡以自訂下載 開發包 為案例下載這個

2.下載得到一個名字為BaiduMap_IOSSDK_v2 的檔案夾  將這個檔案夾拖到自己的項目中

3.申請百度開發秘鑰 http://lbsyun.baidu.com/apiconsole/key 建立應用 填寫相應的東西即可,

注意安全碼要填你的應用bundle ID

4.注意事項 參考  http://developer.baidu.com/map/index.php?title=iossdk/guide/attention

在Info.plist檔案中配置的時候 檔案 大家參考一下

注意在plist檔案中添加一個Bundle display name   string類型   $(PRODUCT_NAME)  就是和Bundle name的名字一樣的 

5.添加 mapapi.bundle檔案 

如果使用了基礎地圖功能,需要添加該資源,否則地圖不能正常顯示

mapapi.bundle中儲存了定位、預設圖釘標註View及路線關鍵點的資源圖片,還儲存了向量地圖繪製必需的資源檔。如果您不需要使用內建的圖片顯示功能,則可以刪除bundle檔案中的image檔案夾。您也可以根據具體需求任意替換或刪除該bundle中image檔案夾的圖片檔案。

方法:選中工程名,在右鍵菜單中選擇Add Files to “工程名”…,從BaiduMapAPI.framework||Resources檔案中選擇mapapi.bundle檔案,並勾選“Copy items if needed”複選框,單擊“Add”按鈕,將資源檔添加到工程中。

6.將你項目中的隨便一個.m檔案的尾碼名變為.mm檔案格式

例如這裡將AppDelegate.m檔案變為AppDelegate.mm檔案格式

7.環境配置

在TARGETS->Build Settings->Other Linker Flags 中添加-ObjC。

8.添加相應的依賴庫

百度地圖SDK中提供了定位功能和動畫效果,v2.0.0版本開始使用OpenGL渲染,因此您需要在您的Xcode工程中引入CoreLocation.framework和QuartzCore.framework、OpenGLES.framework、SystemConfiguration.framework、CoreGraphics.framework、Security.framework、libsqlite3.0.tbd(xcode7以前為 libsqlite3.0.dylib)、CoreTelephony.framework 、libstdc++.6.0.9.tbd(xcode7以前為libstdc++.6.0.9.dylib)。

(註:紅色標識的系統庫為v2.9.0新增的系統庫,使用v2.9.0及以上版本的地圖SDK,務必增加匯入這3個系統庫。)

添加方式:在Xcode的Project -> Active Target ->Build Phases ->Link Binary With Libraries,添加這幾個系統庫即可。

9.在AppDelegate.h檔案中匯入標頭檔

在使用SDK的類 按需 引入下邊的標頭檔:

#import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相關所有的標頭檔

 

#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地圖功能所有的標頭檔

 

#import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入檢索功能所有的標頭檔

 

#import <BaiduMapAPI_Cloud/BMKCloudSearchComponent.h>//引入雲檢索功能所有的標頭檔

 

#import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的標頭檔

 

#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//引入計算工具所有的標頭檔

 

#import <BaiduMapAPI_Radar/BMKRadarComponent.h>//引入周邊雷達功能所有的標頭檔

 

</h//只引入所需的單個標頭檔

 

在AppDelegate.h檔案中建立地圖管理者,我把上述標頭檔全部加到另一個標頭檔中了

直接引用,建立百度地圖管理者

@interface AppDelegate : UIResponder <UIApplicationDelegate,WXApiDelegate>

 

 

@property (strong, nonatomic) UIWindow *window;

/**

 *  百度地圖管理者

 */

@property (nonatomic, strong) BMKMapManager *mapManager;

 

@end

 

在AppDelegate.m檔案中

 

/**

 *  定位

 */

@property (nonatomic, strong) BMKLocationService *locService;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { }

方法中加入

 

//百度地圖

   

//百度地圖

    // 要使用百度地圖,請先啟動BaiduMapManager

    self.mapManager = [[BMKMapManager alloc]init];

    // 如果要關注網路及授權驗證事件,請設定     generalDelegate參數

    BOOL ret = [self.mapManager start:BMKKey  generalDelegate:nil];

    if (!ret) {

        YYCLog(@"百度地圖開啟失敗!");

        

        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"地圖定位開啟失敗!" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles: nil];

        [alert show];

    }else{

        

        self.locService =[[BMKLocationService alloc]init];

        self.locService.delegate = self;

        

        //定位的最小更新距離 100米

        self.locService.distanceFilter=20;

        

        //允許後台定位

        self.locService.allowsBackgroundLocationUpdates=NO;

        

        //啟動LocationService

        [self.locService startUserLocationService];

 

    }

 

#pragma mark - 儲存當前定位經緯度 儲存到本地

-(void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

    [[NSUserDefaults standardUserDefaults] setFloat:userLocation.location.coordinate.latitude forKey:@"latitude"];

    [[NSUserDefaults standardUserDefaults] setFloat:userLocation.location.coordinate.longitude forKey:@"longitude"];

    

    YYCLog(@"latitude:%f,longitude:%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);

    

    

    [self.locService stopUserLocationService];

}

 

 

//百度地圖兩個方法

- (void)onGetNetworkState:(int)iError

{

    if (0 == iError) {

        NSLog(@"連網成功");

    }

    else{

        NSLog(@"onGetNetworkState %d",iError);

    }

    

}

 

- (void)onGetPermissionState:(int)iError

{

    if (0 == iError) {

        NSLog(@"授權成功");

    }

    else {

        NSLog(@"onGetPermissionState %d",iError);

    }

}

//百度地圖

- (void)applicationWillResignActive:(UIApplication *)application

{

    [BMKMapView willBackGround];//當應用即將後台時調用,停止一切調用opengl相關的操作

}

- (void)applicationDidBecomeActive:(UIApplication *)application

{

    [BMKMapView didForeGround];//當應用恢複前台狀態時調用,回複地圖的渲染和opengl相關的操作

}

要用的定位的話直接從本地取出就行了

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.