Xcode4.6 add Baidu Map to the iOS version (Bmapkit) detailed tutorial (_bmkmapmanager Error Resolution)

Source: Internet
Author: User

This article is designed to help beginners quickly build the iOS version of Baidu Map, the official website has related tutorials, but too old, now Xcode has been updated to 4.6, his tutorial should be before 4.3. It is estimated that the novice will encounter errors when building, follow my tutorial step-by-step, to ensure that you spend the least time, rapid map development.

The veteran laugh, I am also a novice, just record the journey, if there are errors, please advise.



Machine Environment: Mac OS X 10.8.2

Development environment: xcode4.6

Real Environment: IPod touch4g Version: 6.1.2


Map version: Baidumapapi_lib_ios_1.2.2:http://developer.baidu.com/map/sdk-ios.htm


"Note": The use of Baidu Map SDK needs to apply for key, the application name can be freely written, if there is Baidu account, the details of the official website to view.



Body


1, download the latest SDK development package _ios Static library file http://developer.baidu.com/map/sdkiosdev-download.htm

Unzip it as shown in the following:



2, open Xcode, create a new demo project (or under your existing project), created after the download of the Inc,libs,mapapi.bundle three folders into the project, attention needs copy+destination, look at me as follows:


Be sure to tick copy and create group to add to target at the same time.


3, almost all third-party map SDKs are dependent on several of Apple's own frameworks, so this step requires us to import: Corelocation.framework and Quartzcore.framework. The import method is as follows:


--------------------------------------------------------------------------------------------------------

At this point, if the. h imports the BMapKit.h header file, instantiates Bmkmapmanager or bmapview, there must be an error like this:



Seemingly hint: LIBBAIDUMAPAPI.A can not find, then is the problem of the path? This is the Bmkmapmanager error that we often encounter. In fact, the principle is that the system can not link to our map static library, the solution is as follows, everyone continue to follow my fourth step (this is only a small attempt and episode, has not set environment variables, will definitely error)

--------------------------------------------------------------------------------------------------------


4, select project, target, switch to Buildsetting label, navigate to other link flag,

Input:-all_load



5, now need to set up the link library environment variables, so that the project can be found in the directory of. A file, select the project, target, switch to the buildsetting tag, navigate to the library search Path, as shown in:


Delete existing three, add a foot (simulator + real machine):$ (srcroot)/libs/release$ (effective_platform_name)

Simply explain:

The $ (SRCROOT) macro represents your project directory, the $ (EFFECTIVE_PLATFORM_NAME) macro represents the current configuration is OS or simulator, this involves environment variables related knowledge, I also do not understand, all is oneself try to come out, Let's just copy my line. As follows:



6, this time, the static library file has been set up, the rest of the only code to work, due to the need for key validation, so we need to use the Bmkmapmanager class, configure the application to the key to be authorized. Select AppDelegate.h

[CPP]View Plaincopy
    1. #import "BMapKit.h"//import BMapKit.h
    2. @interface Appdelegate:uiresponder <uiapplicationdelegate>{
    3. bmkmapmanager* _mapmanager; //Instantiation
    4. }


Select APPDELEGATE.M, change to. MM, (note: The static library is implemented with objectc++, so you need to ensure that you have at least one. mm suffix source file in your project (you can rename any. m suffix file to. mm))

"Note: If there is no mm, the operation will be a large number of error"

In appdelegate.mm , add the following code to the Didfinishlaunchingwithoptions:

[CPP]View Plaincopy
  1. -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
  2. {
  3. //To use Baidu Map, please first start Baidumapmanager
  4. _mapmanager = [[Bmkmapmanager alloc]init];
  5. //If you want to focus on network and authorization validation events, set the Generaldelegate parameter
  6. BOOL ret = [_mapmanager start:@"Fill in the key you entered here" Generaldelegate:nil];
  7. if (!ret) {
  8. NSLog (@"manager start failed!");
  9. }
  10. return YES;
  11. }



7, add the following code to the VIEWCONTROLLER.M that need to display the map:

[CPP]View Plaincopy
    1. #import   "ViewController.h"    
    2. #import   "BMKMapView.h" &NBSP;&NBSP;
    3. &NBSP;&NBSP;
    4. @interface  ViewController  ()   
    5. &NBSP;&NBSP;
    6. @end   
    7. &NBSP;&NBSP;
    8. @implementation  viewcontroller  
    9. &NBSP;&NBSP;
    10. -  (void) viewdidload  
    11. {&NBSP;&NBSP;
    12.     [super viewdidload];  
    13.     bmkmapview* mapview = [[bmkmapview alloc]initwithframe : CGRectMake (0, 0, 320, 460)];  
    14.     self.view =  mapview;  
    15. }&NBSP;&NBSP;


Import bmkmapview class.


8,

(Of course,Bmkmapmanager authorization can also be written to any viewcontroller, but in this case, can only use Mapview in this viewcontroller, for other classes to use the map, but also need to authorize, Otherwise the map view will be a black screen).


Analog device




Real Machine


End

The whole process, the environment variables in the middle of the trouble, but in the future whether the simulator or the real machine debugging, do not have to do any setup, not good?



Xcode4.6 add Baidu Map to the iOS version (Bmapkit) detailed tutorial (_bmkmapmanager Error Resolution)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.