百度地图定位的步骤比较麻烦一点:
详情参见:http://developer.baidu.com/map/wiki/index.php?title=iossdk/guide/hellobaidumap
1.首先在官网下自己所需要的模块。。。生成的头文件与静态文件.a
由于静态文件有模拟器与真机2个。。。故需要把2个静态文件.a合成一个。
打开终端:输入lipo -create 需要空格一下:在把2个.a文件拖入到终端里,最后-output 在把最终生成的文件所在位置托入终端。即可生成。
注意:需要空格。。。没有空格就没法生成
2.静态库中采用ObjectC++实现,因此需要您保证您工程中至少有一个.mm后缀的源文件(您可以将任意一个.m后缀的文件改名为.mm),或者在工程属性中指定编译方式,即将Xcode的Project -> Edit Active Target -> Build -> GCC4.2 - Language -> Compile Sources As设置为"Objective-C++"
3.如果使用Xcode5开发基于iOS7的百度地图应用时,请将Xcode5的Project -> Edit Active Target -> Build -> Linking -> Other Linker Flags中的“-ObjC”修改为“-all_load”
4.需要导入的框架:
CoreLocation.framework和QuartzCore.framework、OpenGLES.framework、SystemConfiguration.framework、CoreGraphics.framework、Security.framework。
5.初始化
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;
}
自2.0.0起,BMKMapView新增viewWillAppear、viewWillDisappear方法来控制BMKMapView的生命周期,并且在一个时刻只能有一个BMKMapView接受回调消息,因此在使用BMKMapView的viewController中需要在viewWillAppear、viewWillDisappear方法中调用BMKMapView的对应的方法,并处理delegate,代码如下:
(void)viewWillAppear:(BOOL)animated
{
[_mapView viewWillAppear];
_mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
}
-(void)viewWillDisappear:(BOOL)animated
{
[_mapView viewWillDisappear];
_mapView.delegate = nil; // 不用时,置nil
}