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
- #import "BMapKit.h"//import BMapKit.h
- @interface Appdelegate:uiresponder <uiapplicationdelegate>{
- bmkmapmanager* _mapmanager; //Instantiation
- }
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
- -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
- {
- //To use Baidu Map, please first start Baidumapmanager
- _mapmanager = [[Bmkmapmanager alloc]init];
- //If you want to focus on network and authorization validation events, set the Generaldelegate parameter
- BOOL ret = [_mapmanager start:@"Fill in the key you entered here" Generaldelegate:nil];
- if (!ret) {
- NSLog (@"manager start failed!");
- }
- return YES;
- }
7, add the following code to the VIEWCONTROLLER.M that need to display the map:
[CPP]View Plaincopy
- #import "ViewController.h"
- #import "BMKMapView.h" &NBSP;&NBSP;
- &NBSP;&NBSP;
- @interface ViewController ()
- &NBSP;&NBSP;
- @end
- &NBSP;&NBSP;
- @implementation viewcontroller
- &NBSP;&NBSP;
- - (void) viewdidload
- {&NBSP;&NBSP;
- [super viewdidload];
- bmkmapview* mapview = [[bmkmapview alloc]initwithframe : CGRectMake (0, 0, 320, 460)];
- self.view = mapview;
- }&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)