Swift integration using the latest version of Baidu map _v2.10.2 (i)

Source: Internet
Author: User

At present in the development of the use of Baidu Map app more and more, I found on the Internet, the integration of Baidu Map example is not many, so I will integrate my Baidu map process recorded down:

First, the premise: installation Cocoapods

sudo gem install Cocoapods

If the installation is successful, there is a hint
Successfully installed CocoaPods

Second, import the Map SDK using Cocoapods

In the folder where the current project file (. xcodeproj) is located, open terminal

1. Create Podfile:

Touch Podfile

2. Edit the Podfile content as follows:

' Baidumapkit ' #百度地图SDK

3. Enter the command in the folder where the Podfile is located: (download here depends on the speed, may be a bit slow)

Pod Install

After success, the following records will appear:

Analyzing dependencies downloading dependencies installing Baidumapkit (2.10. 2 ) generating Pods Project integrating client project

3. Do you think this is the right time to configure it? Don't worry, you need to manually configure the. Framework library, let me take a picture:

4. Note: The static library is implemented in objective-c++, 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 a compilation method in the project properties, that is, in Xcode project- In the Edit Active Target, Build Setting, locate Compile Sources as and set it to "objective-c++".

5. Environment configuration-Add-OBJC in Targets->build settings->other Linker Flags. because my project uses pod here, the pod here has been added by default-OBJC

6. Introduction of Mapapi.bundle Resource files

If you use the underlying map feature, you need to add the resource, otherwise the map does not display properly the resource picture stored in the Mapapi.bundle, the default pin callout view, and the 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_map.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.

7. Introduce the header file and introduce the files you need to add.

#import<baidumapapi_base/bmkbasecomponent.H>Introduce all the header files related to base #import<baidumapapi_map/bmkmapcomponent.H>Introduce all the header files of the map function #import<baidumapapi_search/bmksearchcomponent.H>Introduction of search function All header files   #import <baidumapapi_cloud/bmkcloudsearchcomponent. H>//Introduction to the Cloud Retrieval function All header files   #import <baidumapapi_ Location/bmklocationcomponent. H>//introduction of positioning function All header files   #import <baidumapapi_utils< Span class= "Sy0" >/bmkutilscomponent. h>//introduction of calculation tool All header files   #import < Baidumapapi_radar/bmkradarcomponent. H>//introduction of peripheral radar function All header files   #import < baidumapapi_map< Span class= "Sy0" >/bmkmapview. h>//only the desired single header file is introduced         

8. Apply for the secret key, increase the configuration of HTTPS, add bondle display name.

A: To the Baidu developer platform Application key--http://lbsyun.baidu.com/apiconsole/key, here bundle Identifier is the project bundle Identifier, must fill in the correct.

Two: note: as iOS9 switch to more secure HTTPS, in order to be able to use the Map SDK in IOS9, please configure the following in "Info.plist", otherwise affect the use of the SDK.

<key>nsapptransportsecurity</key>

    <dict<key>nsallowsarbitraryloads</key<true</dict> 

Three: Add key Bundle display name in Info.plist, value fill in Project name.

9. Open Appdelegate.swift file, inherit bmkgeneraldelegate this agent

In

Func Application (application: uiapplication, didfinishlaunchingwithoptions launchoptions: [NSObject : anyobject]?), Bool {Add the following code

  

// test Baidu Map is successful,debug , recommended to open, conducive to debugging programs;release recommended close

_mapmanager=bmkmapmanager()

// If you want to focus on network and authorization validation events, set the generaldelegate parameter

let ret = _mapmanager?. start("Fill in your Application key here", generaldelegate: Self )

if (ret! = Nil) {

NSLog("manager start success!" );

}

if ret = = false {

NSLog("manager start failed!" )

}

}

Baidu map here to complete the integration, encountered a problem can contact me at any time-_-

Swift integration using the latest version of Baidu map _v2.10.2 (i)

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.