iOS add Baidu Map method

Source: Internet
Author: User

Hello baidumapiOS SDK
    • Introducing Header Files
    • Introducing a static library file
    • Introducing the System framework
    • Introducing Mapapi.bundle Resource Files
    • Initialize Bmkmapmanager
    • Create Bmkmapview
Introducing Header Files

First of all Baidu Mapapi provided by the header files and static library (. A) files to your project directory, add a new file group in Xcode, the introduction of Baidu Mapapi provided header files (please use Xcode 4.X above the platform).

Add the following code in the file you need to use Baidu Mapapi

"BMapKit.h"
introducing a static library file

The Baidu Map SDK provides the static library files used by the simulator and the environment in the real machine two, which are stored under the Libs/release-iphonesimulator and Libs/release-iphoneos folders respectively. There are three ways to introduce static library files:

The first way: Drag the corresponding platform's. A file directly to the Groups&files on the left side of the Xcode project, with the disadvantage that it needs to be re-added each time the real machine and emulator are compiled. a file;

The second way: Use the Lipo command to merge the device and emulator. A into a common. A file, drag and drop the merged generic. A file into the project, with the following commands: Lipo-create RELEASE-IPHONEOS/LIBBAIDUMAPAPI.A Release-iphonesimulator/libbaidumapapi.a-output LIBBAIDUMAPAPI.A

The Third Way:

1. Copy the API's Libs folder to your application project root directory

2. Add-OBJC in Linker flags, linking, Build----

3. Set the link path to the static library, and add your static library directory to the library search paths, Build--- such as "$ (srcroot)/. /libs/release$ (Effective_platform_name) ", $ (SRCROOT) macro represents your project file directory, $ (effective_platform_name) The macro represents whether the current configuration is OS or simulator

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

introducing the System framework

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. Add: Right click on the Frameworks folder on the left side of the Xcode project, add->existing frameworks, select the frameworks in the popup window and click Add.

Introducing Mapapi.bundle Resource Files

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. How to add: Copy the Mapapi.bundle to your project directory and drag the bundle file directly to the Groups&files on the left side of the Xcode project. If you need to replace the positioning, compass icon, keep the original file name, otherwise do not display the new picture replaced, the default PIN callout and alignment key new picture name can be customized name.

The SDK resource files contain:

Initialize Bmkmapmanager

Add the definition of Bmkmapmanager in your AppDelegate.h file

@<uiapplicationdelegate{          *window*navigationcontroller; Bmkmapmanager* _mapmanager}      

Add the initialization of the Bmkmapmanager to your APPDELEGATE.M file and fill in the authorization key you requested, as shown below

-(BOOL) application:(uiapplication*) Application Didfinishlaunchingwithoptions:(nsdictionary*) launchoptions{To use Baidu Map, please 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:@ "Enter your authorization key here" Generaldelegate:nil]< Span class= "sy0" >; if  (!ret) {Nslog (@ "manager Start failed!"  //Add the navigation controller ' s view to the window and display. [self. window addsubview:navigationcontroller. View]; [self. Window Makekeyandvisible]; return yes;                /span>             
Create Bmkmapview

Add the Bmkmapview creation code to your VIEWCONTROLLER.M file, such as the following

- (void{[super viewdidload]; Bmkmapview* mapview = [[bmkmapview alloc< Span class= "br0" >]initwithframe:cgrectmake (0, 0, 320, 480) view = mapview;                /span>             

Since 2.0.0, Bmkmapview has added Viewwillappear, viewwilldisappear methods to control the life cycle of Bmkmapview, and only one Bmkmapview accept callback messages at a time, Therefore, in the use of Bmkmapview Viewcontroller need to call Bmkmapview in Viewwillappear, Viewwilldisappear method of the corresponding method, and processing delegate, the code is as follows:

(void) viewwillappear: (BOOL  animated {[_mapview viewwillappear]< Span class= "sy0" >; _mapview. delegate = self; //here remember to need to set nil, otherwise affect the release of memory } - (void) viewwilldisappear: (BOOL  animated {[_mapview viewwilldisappear]< Span class= "sy0" >; _mapview. delegate = nil; //when not in use, place nil }            

Compile, run, and effect as shown:


Baidu Map support multi-touch, double-click Zoom, multi-clicking Zoom, rotation and other gesture operations, in addition, since the 2.2.0 version, the corresponding control interface to enable/disable these gesture operations.

Note: Baidu map iOS SDK since v2.2.0, full implementation of the map multi-instance, that is, developers can build multiple map objects in a page, and for these objects to operate independently and do not create mutual interference. Please refer to the introduction of Multimapviewdemo for the specific use method.

iOS add Baidu Map method

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.