zoukankan      html  css  js  c++  java
  • IOS7学习之路十(百度地图API环境搭建)

    百度地图官网的API开发教程链接:点击打开链接

    我按照他的教程做的总出现Apple Mach-O linker command failed with exit code 1的错误,于是只好自己上网搜了。

    下面说说自己的搭建环境的方法吧   :我错误的原因是引入静态库的时候路径错误导致的

    1.下载链接点击打开链接

    2。解压后如下:


    3.把以上三个inc  libs  mapapi.bundle文件复制粘贴到项目根目录下

    点击Xcode中项目名。原则add projects to"XXX" 把inc文件夹、mapapi.bundle文件和libs/Release-iphoneos文件夹中的libbaidumapapi.a添加到项目中。

    4 几乎所有的第三方地图sdk都是依赖于apple自有的几个framework,所以这一步需要我们导入:CoreLocation.framework和QuartzCore.framework、OpenGLES.framework、SystemConfiguration.framework、CoreGraphics.framework。导入方法如下:



    5.

    引入静态库文件


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

    2).设置静态库的链接路径,在XCode的Project -> Edit Active Target -> Build -> Search Path -> Library Search Paths中添加您的静态库目录,$(SRCROOT)/libs/Release$(EFFECTIVE_PLATFORM_NAME)

    Library Search Paths中这一个就够了把其他的删除

    注:静态库中采用ObjectC++实现,因此需要您保证您工程中至少有一个.mm后缀的源文件(您可以将任意一个.m后缀的文件改名为.mm),或者在工程属性中指定编译方式,即将XCode的Project -> Edit Active Target -> Build -> GCC4.2 - Language -> Compile Sources As设置为"Objective-C++"


    6.

    选中工程,target,切换到Build Setting标签,定位到other link flag,
    输入:-all_load



    7.剩下的就只有代码工作了,由于需要key的验证,所以我们先需要使用BMKMapManager类,配置申请到的key,以得到授权。选中AppDelegate.h

    [plain] view plaincopy
    1. #import "BMapKit.h" //导入BMapKit.h  
    2.   
    3. @interface AppDelegate : UIResponder <UIApplicationDelegate>{  
    4. BMKMapManager* _mapManager; //实例化  
    5. }  
    选中AppDelegate.m,修改成.mm,(注:静态库中采用ObjectC++实现,因此需要您保证您工程中至少有一个.mm后缀的源文件(您可以将任意一个.m后缀的文件改名为.mm))
    【注意:如果没有mm,运行会大量报错的】
    在AppDelegate.mm中的didFinishLaunchingWithOptions,加入如下代码:
    [plain] view plaincopy
    1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
    2. {  
    3.     // 要使用百度地图,请先启动BaiduMapManager  
    4.     _mapManager = [[BMKMapManager alloc]init];  
    5.     // 如果要关注网络及授权验证事件,请设定generalDelegate参数  
    6.     BOOL ret = [_mapManager start:@"你申请的ak" generalDelegate:nil];  
    7.     if (!ret) {  
    8.         NSLog(@"manager start failed!");  
    9.     }  
    10.     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];  
    11.     // Override point for customization after application launch.  
    12.     self.viewController = [[[ZYViewController alloc] initWithNibName:@"ZYViewController" bundle:nil] autorelease];  
    13.     self.window.rootViewController = self.viewController;  
    14.     [self.window makeKeyAndVisible];  
    15.     return YES;  
    16. }  

    8 在需要显示地图的viewcontroller.m中加入如下代码:

    [plain] view plaincopy
    1. #import "ViewController.h"  
    2. #import "BMKMapView.h"  
    3.   
    4. @interface ViewController ()  
    5.   
    6. @end  
    7.   
    8. @implementation ViewController  
    9.   
    10. - (void)viewDidLoad  
    11. {  
    12. [super viewDidLoad];  
    13. BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];  
    14. self.view = mapView;  
    15. }  

    导入BMKMapView.h后,实例化BMKMapView类。


    自2.0.0起,BMKMapView新增viewWillAppear、viewWillDisappear方法来控制BMKMapView的生命周期,并且在一个时刻只能有一个BMKMapView接受回调消息,因此在使用BMKMapView的viewController中需要在viewWillAppear、viewWillDisappear方法中调用BMKMapView的对应的方法,并处理delegate,代码如下:

    1. (void)viewWillAppear:(BOOL)animated    
    2. {    
    3.     [_mapView viewWillAppear];    
    4.     _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放    
    5. }    
    6. -(void)viewWillDisappear:(BOOL)animated    
    7. {    
    8.     [_mapView viewWillDisappear];    
    9.       _mapView.delegate = nil; // 不用时,置nil    
    10. }    

    编译,运行,效果如下图所示:



  • 相关阅读:
    Learning Experience of Big Data:The First Day-Try to set up a network connection on my virtural machine
    Learning Experience of Big Data: Learn to install CentOs 6.5 on my laptop
    事物总线模式实例——EventBus实例详解
    软件架构——事件总线模式
    阅读《大型网站技术架构》,并结合"重大需求征集系统"有感
    淘宝网的六个质量属性
    读架构漫谈博文有感
    06软件需求读书笔记(六)
    .NET应用程序性能优化
    【转】消息队列设计精要
  • 原文地址:https://www.cnblogs.com/lixingle/p/3707697.html
Copyright © 2011-2022 走看看