IOS學習:在工程中添加百度地圖SDK

來源:互聯網
上載者:User

 

     1、將下載下來的sdk中的inc檔案夾、mapapi.bundle、libbaidumapapi.a添加到工程中,其中libbaiduapi.a有兩個,一個對應模擬器一個對應真機,匯入方法如下:


第一種方式:直接將對應平台的.a檔案拖拽至XCode工程左側的Groups&Files中,缺點是每次在真機和模擬器編譯時間都需要重新添加.a檔案;

第二種方式:使用lipo命令將裝置和模擬器的.a合并成一個通用的.a檔案,將合并後的通用.a檔案拖拽至工程中即可,具體命令如下:
lipo –create Release-iphoneos/libbaidumapapi.a Release-iphonesimulator/libbaidumapapi.a –output libbaidumapapi.a

第三種方式:

               1.將API的libs檔案夾拷貝到您的Application工程跟目錄下

               2.在XCode的Project -> Edit Active Target -> Build -> Linking -> Other Linker Flags中添加-ObjC

                3.設定靜態庫的連結路徑,在XCode的Project -> Edit Active Target -> Build -> Search Path -> Library Search Paths中添加您的靜態庫目錄,比                         如"$(SRCROOT)/../libs/Release$(EFFECTIVE_PLATFORM_NAME)",$(SRCROOT)宏代表您的工程檔案目錄,$(EFFECTIVE_PLATFORM_NAME)宏代表當前配置是OS還是simulator


我是用第二種方法,在真機和模擬器下都可以調試。


     2、因為靜態庫採用Object C++實現,所以在工程中至少要有一個.mm的檔案存在(可以把appdelegate.m改為.mm)


     3、匯入工程所需的架構:CoreLocation.framework,QuartzCore.framework,OpenGLES.framework,SystemConfiguration.framework


     4、在AppDelegate中添加BMKMapManager對象,這裡要在百度地圖api網站上申請一個應用key
AppDelegate.h檔案如下:


[cpp]
#import <UIKit/UIKit.h>  
#import "TestViewController.h"  
#import "BMapKit.h"  
 
#define BaiduMapKey @"A56A733C30B159166B74AD41530CB013685035F9"  
 
@interface AppDelegate : UIResponder <UIApplicationDelegate> { 
    BMKMapManager* _mapManager; 

 
@property (strong, nonatomic) UIWindow *window; 
 
@end 

#import <UIKit/UIKit.h>
#import "TestViewController.h"
#import "BMapKit.h"

#define BaiduMapKey @"A56A733C30B159166B74AD41530CB013685035F9"

@interface AppDelegate : UIResponder <UIApplicationDelegate> {
    BMKMapManager* _mapManager;
}

@property (strong, nonatomic) UIWindow *window;

@end

 


AppDelegate.m檔案如下:


[cpp]
 (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

    _mapManager = [[BMKMapManageralloc] init]; 
    BOOL ret = [_mapManagerstart:BaiduMapKey generalDelegate:nil]; 
    if (!ret) { 
        NSLog(@"BMKMapManager start failed!"); 
    } 
    
    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]]; 
    // Override point for customization after application launch.  
    self.window.backgroundColor = [UIColorwhiteColor]; 
    
    TestViewController *root = [[TestViewControlleralloc] init]; 
    self.window.rootViewController = root; 
    
    [self.windowmakeKeyAndVisible]; 
    returnYES; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    _mapManager = [[BMKMapManageralloc] init];
    BOOL ret = [_mapManagerstart:BaiduMapKey generalDelegate:nil];
    if (!ret) {
        NSLog(@"BMKMapManager start failed!");
    }
  
    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColorwhiteColor];
  
    TestViewController *root = [[TestViewControlleralloc] init];
    self.window.rootViewController = root;
  
    [self.windowmakeKeyAndVisible];
    returnYES;
}

 

相關文章

聯繫我們

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