Integration of iOS development with Baidu map (based on Xcode7.0/iOS9.2) and xcode7.0ios9.2

Source: Internet
Author: User

Integration of iOS development with Baidu map (based on Xcode7.0/iOS9.2) and xcode7.0ios9.2

This article describes how to integrate a hundred-degree map in four steps:

Step 1: Create a project Step 2: Use cocoaPod to import Baidu map SDK (pod 'baidumapkit' # Baidu map SDK) Step 3: import the header file and key in the pch File

Key is in http://lbsyun.baidu.com/apiconsole/key Baidu open platform application.

#define APPKEY @"UzyiXewPsqPhcE1yS8wxqik9"

Introduce the following header file as needed when using the SDK class

# Import <baidumapi_base/BMKBaseComponent. h> // introduce all base-related header files # import <BaiduMapAPI_Map/BMKMapComponent. h> // introduce all header files of the map function # import <baidumapi_search/BMKSearchComponent. h> // introduce all header files of the search function # import <BaiduMapAPI_Cloud/BMKCloudSearchComponent. h> // introduce all header files of the cloud search function # import <BaiduMapAPI_Location/BMKLocationComponent. h> // introduce all header files of the positioning function # import <BaiduMapAPI_Utils/BMKUtilsComponent. h> // introduce all the header files of the computing tool # import <baidumapi_radar/BMKRadarComponent. h> // introduce all the header files of the peripheral radar function # import <BaiduMapAPI_Map/BMKMapView. h> // only introduce a single header file
Step 4: load the Map Manager in the AppDelegate. m file
- (BMKMapManager *)mapManager {    if (!_mapManager) {        _mapManager = [[BMKMapManager alloc] init];        BOOL ret = [_mapManager start:APPKEY generalDelegate:nil];        if (!ret) {            NSLog(@"manager start failed!");        } else {            NSLog(@"manager start success!");        }    }    return _mapManager;}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.    [self mapManager];    return YES;}

In this step, we can run Baidu map normally.

However, the following information is output on the console:

We will configure the Bundle display name in the plist file step by step as required. In fact, this is the information to be configured in Xcode6, which is not required in Xcode7.

<key>CFBundleDisplayName</key><string>$(PRODUCT_NAME)</string>

The Map Manager loads the data again. However, since iOS9 uses a safer https, in order to use the Baidu map SDK properly in iOS9, You need to inject ATS

<key>NSAppTransportSecurity</key><dict>    <key>NSAllowsArbitraryLoads</key>    <true/></dict>

At this time, although no error is reported, the manager loads the map successfully and the map mesh also exists, but the map details cannot be displayed.

At this time, check whether your key is correct. I made a mistake once and ensure that the security code of the applied key is consistent with the Bundle Identifier of the project.

At this time, Baidu map was successfully integrated.

 

Note: No configuration is made for the description in this article.

When the app switches between the front and back ends, you need to use the following code to stop rendering the map and openGL:

-(Void) applicationWillResignActive :( UIApplication *) application {[BMKMapView willBackGround]; // when the application is about to be called in the background, stop all opengl-related operations.}-(void) applicationDidBecomeActive :( UIApplication *) application {[BMKMapView didForeGround]; // when the application returns to the foreground state, it is called to reply to map rendering and opengl-related operations}

Related Article

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.