Detailed steps for iOS Baidu map SDK integration and iossdk Integration

Source: Internet
Author: User

Detailed steps for iOS Baidu map SDK integration and iossdk Integration

1. iOS Baidu map http://developer.baidu.com/map/index.php? Title = iossdk/sdkiosdev-download

Select different versions as needed. Here we use the custom download SDK as the example to download this

2. Download a folder named BaiduMap_IOSSDK_v2 and drag it to your project.

3. Apply for Baidu Development Key http://lbsyun.baidu.com/apiconsole/key to create an application to fill in the corresponding stuff,

Note that you must enter your application bundle ID in the security code.

4. considerations refer to http://developer.baidu.com/map/index.php? Title = iossdk/guide/attention

Refer to the configuration file in the Info. plist File

Note that adding a Bundle display name string type in the plist File $ (PRODUCT_NAME) is the same as the Bundle name

5. Add the mapapi. bundle File

If you use the basic map function, you need to add the resource. Otherwise, the map cannot be displayed normally.

Mapapi. bundle stores resource images for locating, marking View and route key points by default, and also stores necessary resource files for vector map rendering. If you do not need the built-in image display function, you can delete the image folder in the bundle file. You can also replace or delete the image files in the image folder of the bundle as needed.

Method: select the project name, right-click the project name, and choose Add Files to "project name "..., Select the mapapi. bundle file from the BaiduMapAPI. framework | Resources file, select the Copy items if needed check box, and click the Add button to Add the resource file to the project.

6. Change the suffix of any. m file in your project to. mm file format.

For example, change the AppDelegate. m file to the AppDelegate. mm file format.

7. Environment Configuration

Add-ObjC to TARGETS-> Build Settings-> Other Linker Flags.

8. Add the corresponding dependent Library

Baidu map SDK provides positioning and animation effects. In v2.0.0, OpenGL is used for rendering. Therefore, you need to introduce CoreLocation in your Xcode project. framework and QuartzCore. framework, OpenGLES. framework, SystemConfiguration. framework, CoreGraphics. framework, Security. framework, libsqlite3.0.tbd (libsqlite3.0.dylib before xcode7), CoreTelephony. framework, libstdc ++. 6.0.9.tbd (xcode7 was previously libstdc ++. 6.0.9.dylib ).

(Note: The system library marked in red is the new system library v2.9.0. To use the map SDK v2.9.0 or a later version, you must add and import these three system libraries .)

Add the system Libraries in Xcode Project> Active Target> Build Phases> Link Binary With Libraries.

9. Import the header file in the AppDelegate. h file.

Introduce the following header file as needed in the SDK class:

# Import <baidumapi_base/BMKBaseComponent. h> // introduce all base-related header files.

 

# Import <baidumapi_map/BMKMapComponent. h> // import all header files of the map function

 

# Import <baidumapi_search/BMKSearchComponent. h> // introduce all header files of the search function

 

# Import <baidumapi_cloud/BMKCloudSearchComponent. h> // introduce all header files of the cloud search function

 

# Import <baidumapi_location/BMKLocationComponent. h> // introduce all header files of the positioning function

 

# Import <baidumapi_utils/BMKUtilsComponent. h> // introduce all header files of the computing tool.

 

# Import <baidumapi_radar/BMKRadarComponent. h> // introduce all header files of the peripheral radar Function

 

</H // only introduce a single header file

 

Create a Map Manager in the AppDelegate. h file. I added all the above header files to another header file.

Directly reference and create Baidu Map Manager

@ Interface AppDelegate: UIResponder <UIApplicationDelegate, WXApiDelegate>

 

 

@ Property (strong, nonatomic) UIWindow * window;

/**

* Baidu Map Manager

*/

@ Property (nonatomic, strong) BMKMapManager * mapManager;

 

@ End

 

In the AppDelegate. m file

 

/**

* Positioning

*/

@ Property (nonatomic, strong) BMKLocationService * locService;

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {}

Add to Method

 

// Baidu Map

// Baidu Map

// To use Baidu map, start BaiduMapManager first

Self. mapManager = [[BMKMapManager alloc] init];

// If you want to pay attention to network and authorization verification events, set the generalDelegate parameter.

BOOL ret = [self. mapManager start: BMKKey generalDelegate: nil];

If (! Ret ){

YYCLog (@ "Baidu map opening failed! ");

UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "An error occurred while enabling map locating! "Message: nil delegate: nil cancelButtonTitle: @" cancel "otherButtonTitles: nil];

[Alert show];

} Else {

Self. locService = [[BMKLocationService alloc] init];

Self. locService. delegate = self;

// The minimum update distance for positioning is 100 meters.

Self. locService. distanceFilter = 20;

// Allows background location

Self. locService. allowsBackgroundLocationUpdates = NO;

// Start LocationService

[Self. locService startUserLocationService];

 

}

 

# Pragma mark-stores the currently positioned longitude and latitude data stored locally

-(Void) didUpdateBMKUserLocation :( BMKUserLocation *) userLocation

{

[[NSUserDefaults standardUserDefaults] setFloat: userLocation. location. coordinate. latitude forKey: @ "latitude"];

[[NSUserDefaults standardUserDefaults] setFloat: userLocation. location. coordinate. longpolling forKey: @ "longpolling"];

YYCLog (@ "latitude: % f, longpolling: % f", userLocation. location. coordinate. latitude, userLocation. location. coordinate. longpolling );

[Self. locService stopUserLocationService];

}

 

 

// Baidu Map

-(Void) onGetNetworkState :( int) iError

{

If (0 = iError ){

NSLog (@ "Networking successful ");

}

Else {

NSLog (@ "onGetNetworkState % d", iError );

}

}

 

-(Void) onGetPermissionState :( int) iError

{

If (0 = iError ){

NSLog (@ "Authorization successful ");

}

Else {

NSLog (@ "onGetPermissionState % d", iError );

}

}

// Baidu Map

-(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]; // This API is called when the application returns to the foreground state. It replies to map rendering and opengl-related operations.

}

If you want to use the location, simply retrieve it from the local device.

 

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.