1、在Xcode的Project -> Edit Active Target -> Build Setting 中找到 Compile Sources As,并将其设置为"Objective-C"
2、在Xcode的Project -> Edit Active Target -> Build Setting -> Other Linker Flags中添加-ObjC
3、测试用的bundleID:com.baidu.mapsdk.demo.IphoneMapSdkDemo Key:Bj3oVaDCjqsTXtnSOBdGhjPY33IMKieK 可以是百度开放平台自己申请
4、由于iOS9改用更安全的https,为了能够在iOS9中正常使用地图SDK,请在"Info.plist"中进行如下配置NSAppTransportSecurity NSAllowsArbitraryLoads,否则影响SDK的使用。
5、如果在iOS9中使用了调起百度地图客户端功能,必须在"Info.plist"中进行如下配置,否则不能调起百度地图客户端。LSApplicationQueriesScheme sbaidumap
6、在需要掉起百度地图的控制器viewWillAppear、viewWillDisappear中添加:
-(void)viewWillAppear:(BOOL)animated { [_mapView viewWillAppear]; _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放 }
-(void)viewWillDisappear:(BOOL)animated { [_mapView viewWillDisappear]; _mapView.delegate = nil; // 不用时,置nil }
7、自iOS SDK v2.5.0起,为了对iOS8的定位能力做兼容,做了相应的修改,开发者在使用过程中注意事项如下: 需要在info.plist里添加(以下二选一,两个都添加默认使用NSLocationWhenInUseUsageDescription):NSLocationWhenInUseUsageDescription ,允许在前台使用时获取GPS的描述NSLocationAlwaysUsageDescription ,允许永久使用GPS的描述8、在使用Xcode6进行SDK开发过程中,需要在info.plist中添加:Bundle display name ,且其值不能为空(Xcode6新建的项目没有此配置,若没有会造成manager start failed)
![](https://img.haomeiwen.com/i3150942/10d1f12604bffcc5.png)
9、导入sdk开发包,导入系统库:
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)。
10、引入mapapi.bundle资源文件 选中工程名,在右键菜单中选择Add Files to “工程名”…,从BaiduMapAPI_Map.framework||Resources文件中选择mapapi.bundle文件,并勾选“Copy items if needed”复选框,单击“Add”按钮,将资源文件添加到工程中11、引入头文件#import//引入base相关所有的头文件 #import//引入地图功能所有的头文件 #import//引入检索功能所有的头文件 #import//引入云检索功能所有的头文件 #import//引入定位功能所有的头文件 #import//引入计算工具所有的头文件 #import//引入周边雷达功能所有的头文件 #import//只引入所需的单个头文件12、在您的AppDelegate.h文件中添加BMKMapManager的定义
@interface BaiduMapApiDemoAppDelegate : NSObject{
UIWindow *window;
UINavigationController *navigationController;
BMKMapManager* _mapManager;
}
在您的AppDelegate.m文件中添加对BMKMapManager的初始化,并填入您申请的授权Key,示例如下
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 要使用百度地图,请先启动BaiduMapManager
_mapManager = [[BMKMapManager alloc]init]; // 如果要关注网络及授权验证事件,请设定 generalDelegate参数
BOOL ret = [_mapManager start:@"在此处输入您的授权Key" generalDelegate:nil]; if (!ret) { NSLog(@"manager start failed!"); } // Add the navigation controller's view to the window and display.
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES; }
13、创建bmkMapView在您的ViewController.m文件中添加BMKMapView的创建代码,示例如下
- (void)viewDidLoad {
[super viewDidLoad];
BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; self.view = mapView;
}
14、定位服务
-(void)viewDidLoad
{
//初始化BMKLocationService
_locService = [[BMKLocationService alloc]init];
_locService.delegate = self;
//启动LocationService
[_locService startUserLocationService];
}
//实现相关delegate 处理位置信息更新
//处理方向变更信息
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
//NSLog(@"heading is %@",userLocation.heading);
}
//处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
//NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
}
Notice:项目开发过程中遇到的梗
1、41个error 好吧 在Xcode的Project -> Edit Active Target -> Build Setting 中找到 Compile Sources As,并将其设置为"Objective-C"
2、mapapi.bundle找不到 去demo扒一下
https://github.com/pengjinguang521/BaiduMapDemoTest.git
网友评论