欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

IOS学习:在工程中添加百度地图SDK

来源: 开发者 投稿于  被查看 44476 次 评论:194

IOS学习:在工程中添加百度地图SDK


 

     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;
}

 

相关文章

    暂无相关文章

用户评论