IOS learning: Add Baidu map SDK to the Project

Source: Internet
Author: User

 

1. The downloaded sdk contains the inc folder and mapapi. bundle, libbaidumapapi. a is added to the project, in which libbaiduapi. a has two, one corresponding to the simulator and the other corresponding to the real machine. The import method is as follows:


Method 1: drag the. a file of the corresponding platform to the Groups & Files on the left side of the XCode project. The disadvantage is that the. a file needs to be re-added every time the real machine and simulator are compiled;

Method 2: Use the lipo command to connect devices and simulators. a is merged into a common one. file. drag the file to the project. The specific command is as follows:
Lipo-create Release-iphoneos/libbaidumapapi. a Release-iphonesimulator/libbaidumapapi. a-output libbaidumapapi.

Method 3:

1. Copy the libs folder of the API to your Application project and directory.

2. Add-ObjC to XCode Project> Edit Active Target> Build> Linking> Other Linker Flags.

3. set the link Path of the static Library, and add your static Library directory to XCode Project> Edit Active Target> Build> Search Path> Library Search Paths, for example, "$ (SRCROOT )/.. /libs/Release $ (inclutive_platform_name) ", $ (SRCROOT) macro represents your project file directory, $ (inclutive_platform_name) macro represents whether the current configuration is OS or simulator


I am using the second method, which can be debugged on both the real machine and the simulator.


2. Because the static library uses Object C ++, at least one. mm file must exist in the project (you can change appdelegate. m to. mm)


3. frameworks required for project import: CoreLocation. framework, QuartzCore. framework, OpenGLES. framework, and SystemConfiguration. framework


4. Add the BMKMapManager object to AppDelegate. Here, you need to apply for an application key on the Baidu map api website.
The AppDelegate. h file is as follows:


[Cpp]
# Import <UIKit/UIKit. h>
# Import "TestViewController. h"
# Import "BMapKit. h"
 
# Define BaiduMapKey @ "a56a733c30b159166b74ad41030cb013685035f9"
 
@ Interface AppDelegate: UIResponder <UIApplicationDelegate> {
BMKMapManager * _ mapManager;
}
 
@ Property (strong, nonatomic) UIWindow * window;
 
@ End

# Import <UIKit/UIKit. h>
# Import "TestViewController. h"
# Import "BMapKit. h"

# Define BaiduMapKey @ "a56a733c30b159166b74ad41030cb013685035f9"

@ Interface AppDelegate: UIResponder <UIApplicationDelegate> {
BMKMapManager * _ mapManager;
}

@ Property (strong, nonatomic) UIWindow * window;

@ End

 


The AppDelegate. m file is as follows:


[Cpp]
(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
_ MapManager = [[BMKMapManageralloc] init];
BOOL ret = [_ mapManagerstart: BaiduMapKey generalDelegate: nil];
If (! Ret ){
NSLog (@ "BMKMapManager start failed! ");
}

Self. window = [[uiappswalloc] initWithFrame: [UIScreenmainScreen] bounds];
// Override point for customization after application launch.
Self. window. backgroundColor = [UIColorwhiteColor];

TestViewController * root = [[TestViewControlleralloc] init];
Self. window. rootViewController = root;

[Self. windowmakeKeyAndVisible];
ReturnYES;
}

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
_ MapManager = [[BMKMapManageralloc] init];
BOOL ret = [_ mapManagerstart: BaiduMapKey generalDelegate: nil];
If (! Ret ){
NSLog (@ "BMKMapManager start failed! ");
}

Self. window = [[uiappswalloc] initWithFrame: [UIScreenmainScreen] bounds];
// Override point for customization after application launch.
Self. window. backgroundColor = [UIColorwhiteColor];

TestViewController * root = [[TestViewControlleralloc] init];
Self. window. rootViewController = root;

[Self. windowmakeKeyAndVisible];
ReturnYES;
}

 

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.