"IOS" Baidu Map API Usage Summary

Source: Internet
Author: User

First, need to Baidu lbs open platform Registered developer account, this step slightly.

The IOS SDK has started with a new key verification system since the v2.0.2 release. To use the Baidu Map SDK in a project, you must apply for the corresponding key.



Application name to fill in the name of the project, the application type according to the need to choose, the service can be all checked, can also be checked as required, security code is the project bundle Identifier



Click Submit to generate a new key.


This part of the AK is your project-specific key, to be written in the appdelegate.


Part II Configuration

This part is to refer to the method provided by Baidu, according to step is not wrong.

configuration. Framework Form Development Package


The first step, the introduction of Baidumapapi.framework

The Baidu Map SDK provides the framework used by the simulator and the real machine in two environments, stored in the Libs/release-iphonesimulator and Libs/release-iphoneos folders, respectively, Developers can use the real machine or simulator packages as needed, and if you need to use both the real and emulator packages, you can use the Lipo command to merge the Baidumapapi files from the device and emulator Framwork package into a common file, with the following command: Lipo-create Release-iphoneos/baidumapapi.framework/baidumapapi Release-iphonesimulator/baidumapapi.framework/baidumapapi- Output Release-iphoneos/baidumapapi.framework/baidumapapi

The baidumapapi.framework under the Release-iphoneos folder is now available for both the real machine and the emulator (you can use the Lipo–info command to check the schema supported by the framework).

Copy the required baidumapapi.framework to the folder where the project is located. Click the "+" button in the Targets->build phases-> Link Binary with libaries and click the "Add Other" button in the pop-up window. Select the Baidumapapi.framework file to add to the project.

Note: The static library is implemented in 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), or specify the compilation method in the project properties, and Edit the Xcode project, Compile Sources as set to "objective-c++", Build-Gcc4.2-language, Active Target

The second step, the introduction of the required system library

The Baidu Map SDK provides positioning and animation effects, and the v2.0.0 version starts using OpenGL rendering, so you need to introduce Corelocation.framework and quartzcore.framework in your Xcode project, Opengles.framework, Systemconfiguration.framework, Coregraphics.framework, Security.framework. How to add: add these frameworks in the Xcode project, Active Target->build phases->link Binary with Libraries.

The third step, environment configuration

Add-OBJC in the Targets->build settings->other Linker Flags.

Fourth step, introduce Mapapi.bundle resource file

If you use the underlying map feature, you need to add the resource, or the map will not display properly

Mapapi.bundle stores a resource picture of location, default pin callout view, and Route key, and also stores the necessary resource files for vector map drawing. If you do not need to use the built-in picture display feature, you can delete the image folder in the bundle file. You can also arbitrarily replace or delete the image file of the image folder in the bundle according to your specific needs.

Method: Select the project name, select Add Files to "project name" in the right-click menu, from baidumapapi.framework| | Resources file, select the Mapapi.bundle file and tick the "Copy items if needed" check box and click the "Add" button to add the resource file to the project.


Fifth step, introduce the header file

Introduce the header file in the class using the SDK:

 #import <  baidumapapi/ Bmapkit.h  >  //introduces all header files    #import <  Baidumapapi/ bmkmapview.h  >  //only introduces the desired single-header file  
And it's three points to note.

1. add-OBJC in Targets->build settings->other Linker Flags


2.info.plist


Here is the need to manually add it, or iOS8 above the operation will be error, or location failure


If the emulator cannot be located, change the emulator location to None,debug-->location-->none


Also, there must be at least one. mm file in the project, or you will get an error.

According to Baidu's saying:

The static library is implemented in 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), or specify the compilation method in the project properties, and Edit the Xcode project, Compile Sources as set to "objective-c++", Build-Gcc4.2-language, Active Target

But the personal habit is to change the filename, otherwise objective-c++ and objective-c should be enough trouble.


Code issues:

Appdelegate.m


-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions;

in this method, call the following method.

If you want to use Baidu map, first start baidumapmanager    mapmanager = [[Bmkmapmanager alloc] init];        If you need to focus on network and authorization authentication events, to set the generaldelegate parameter to self    //If you do not need to focus on network and authorization validation events, set the Generaldelegate parameter to nil    BOOL ret = [ Mapmanager start:@ "Xfoaoagajwxsk0ahn0adcobn" generaldelegate:self];    if (!ret) {        NSLog (@ "manager start failed");    }

IOS8 Start positioning-(BOOL) beginlocationupdate{    //Determine if the location operation is allowed    if ([Cllocationmanager locationservicesenabled])    {        Locationmanager = [[Cllocationmanager alloc] init];//Note that the Locationmanager here is not a local variable        //compatible iOS8 locating        SEL Requestselector = nsselectorfromstring (@ "requestwheninuseauthorization");        if ([cllocationmanager authorizationstatus] = = kclauthorizationstatusnotdetermined &&            [Locationmanager Respondstoselector:requestselector]) {            [Locationmanager requestwheninuseauthorization];        }        return YES;    } else {        //Prompt user for no positioning operation            }    return no;

#pragma mark-processing of network status monitoring-(void) Ongetnetworkstate: (int) ierror{    if (0 = = ierror) {        NSLog (@ "Networking success");    }    else{        NSLog (@ "Ongetnetworkstate%d", ierror);}    } #pragma mark-key Authorization status monitoring-(void) Ongetpermissionstate: (int) ierror{    if (0 = = ierror) {        NSLog (@ "authorized success");    }    else {        NSLog (@ "Ongetpermissionstate%d", ierror);}    }

Viewcontroller is not written in the first. This can refer to Baidu Map official demo Locationdemoviewcontroller, the basic is the same, no problem.








"IOS" Baidu Map API Usage Summary

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.