申请key
● http://lbsyun.baidu.com/apiconsole/key
下载SDK
● 最新版本
开发指南
● http://developer.baidu.com/map/sdkiosdev-1.htm
开发包结构
集成开发包
-
合并真机和模拟器的.a库文件
-
添加依赖的.a、.h、framework、bundle等资源
-
新建.mm文件
-
修改软件唯一标识
-
导入主头文件
-
开启地图引擎
-
地图展示
1.合并真机和模拟器的.a库文件
.百度地图并未开源,只提供了静态库文件libbaidumapapi.a,有真机和模拟器版,分别 放在下面两个文件夹中:
。BaiduMap_iOSSDK_v2.1.0_Lib/libs/Release-iphoneos
。BaiduMap_iOSSDK_v2.1.0_Lib/libs/Release-iphonesimulator
。为了避免每次在真机和模拟器编译时都重新添加.a文件,应该将两个.a文件合并为一 个,在终端上输入一下指令:
。cd /这里是百度地图SDK根路径/BaiduMap_iOSSDK_v2.1.0_Lib/libs
。lipo -create Release-iphoneos/libbaidumapapi.a Releaseiphonesimulator/libbaidumapapi.a -output libbaidumapapi.a
。然后就会在libs文件夹下产生一个libbaidumapapi.a文件
2.添加依赖的.a、.h、framework、bundle等资源
● CoreLocation.framework
● QuartzCore.framework
● OpenGLES.framework
● SystemConfiguration.framework
● CoreGraphics.framework
● Security.framework(2.1.0开始需要)
3.新建.mm文件
4.修改软件唯一标识
5.导入主头文件
6.开启地图引擎
int ret =[_mapMgr
start:@"0F0dd93edfd75399dc65e299305b8490"
generalDelegate:nil];
if (ret) { MyLog(@"地图引擎开启成功!");
} start后面传递的是申请的key
7.地图展示
● 添加展示地图的BMKMapView
[self.view addSubview:_mapView];
#import "HMViewController.h" #import "BMapKit.h" @interface HMViewController () <BMKGeneralDelegate, BMKPoiSearchDelegate> @property (nonatomic, strong) BMKMapManager *mgr; @property (nonatomic, strong) BMKPoiSearch *search; @end @implementation HMViewController - (void)viewDidLoad { [super viewDidLoad]; // 地图引擎管理类 self.mgr = [[BMKMapManager alloc] init]; [self.mgr start:@"rnPqE3HLgPQtCEaYpZ6BFeX8" generalDelegate:self]; // 添加地图控件 BMKMapView *mapView = [[BMKMapView alloc] init]; mapView.frame = self.view.bounds; [self.view addSubview:mapView]; // self.search = [[BMKPoiSearch alloc] init]; // self.search.delegate = self; // [self.search poiSearchInCity:<#(BMKCitySearchOption *)#>]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - BMKGeneralDelegate - (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); } } #pragma mark - BMKPoiSearchDelegate - (void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPoiResult *)poiResult errorCode:(BMKSearchErrorCode)errorCode { // for (BMKPoiInfo *info in poiResult.poiInfoList) { // // } } @end