IOS Baidu map --- & gt; Article 1 Environment configuration and basic use, Baidu map sdkios

Source: Internet
Author: User

IOS Baidu map ---> Article 1 Environment configuration and basic use, Baidu map sdkios

Ios Baidu map SDK easy use instructions: http://developer.baidu.com/map/index.php? Title = iossdk

Sorry first: I am sorry for the Demo I uploaded. I have nothing and no documentation. This time, I will gradually add related functions in the SDK (based on Baidu Simple ), if I cannot write well, please include more;

Step 1: Merge static files

Lipo-create Release-iphoneos/libbaidumapapi. a Release-iphonesimulator/libbaidumapapi. a-output libbaidumapapi.

Note: directories may be inconsistent.

Step 2: configure the environment

1. Add-ObjC to Xcode Project> Edit Active Target> Build> Linking> Other Linker Flags.

2. Introduce the frameWork to introduce CoreLocation. framework, QuartzCore. framework, OpenGLES. framework, SystemConfiguration. framework, CoreGraphics. framework, and Security. framework.

3. Modify the suffix of A. m file to. mm. Then, test whether the project is normal.

4. Add pch (optional)

5. Since iOS SDK v2.5.0, the following changes have been made to ensure compatibility with the positioning capability of iOS8: info. add in plist (either of the following, and both of them use NSLocationWhenInUseUsageDescription by default): NSLocationWhenInUseUsageDescription, which allows you to obtain the NSLocationAlwaysUsageDescription of GPS during foreground use and allows you to use GPS permanently.

6. During SDK development using Xcode6. add: Bundle display name in plist, and its value cannot be blank (this configuration is not available for the project created in Xcode6. If no configuration is available, the manager start failed will be caused );

7. The viewWillAppear and viewWillDisappear methods are added to BMKMapView to control the lifecycle of BMKMapView. In addition, only one BMKMapView can receive callback messages at a time. Therefore, BMKMapView is used.

In viewController, you need to call the corresponding method of BMKMapView in the viewWillAppear and viewWillDisappear methods and process the delegate. The Code is as follows:

-(Void) viewWillAppear :( BOOL) animated

{

[_ MapViewviewWillAppear];

_ MapView. delegate = self; // set nil when you do not need it here; otherwise, the memory will be released.

// Start LocationService

[_ LocationServicestartUserLocationService];

}

-(Void) viewWillDisappear :( BOOL) animated

{

[_ MapViewviewWillDisappear];

_ MapView. delegate = nil; // when not in use, set nil

}

Step 3: basic usage Loading

1. Reference # import "BMapKit. h" and declare it in AppDelegate. h.

@ Interface AppDelegate: UIResponder <UIApplicationDelegate>

 

@ Property (strong, nonatomic) UIWindow * window;

@ Property (strong, nonatomic) BMKMapManager * mapManager;

 

@ End

2. In AppDelegate. m

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

// Override point for customization after application launch.

_ MapManager = [[BMKMapManageralloc] init];

// BaiduMapKey the Baidu map AK you applied for (macro definition)

If (! [_ MapManagerstart: BaiduMapKeygeneralDelegate: self])

{

KHLog (@ "failed to start"); // KHLog is equivalent to NSLog

}

ReturnYES;

}

-(Void) onGetNetworkState :( int) iError

{

If (iError = 0)

{

KHLog (@ "network status is normal ");

}

Else

{

KHLog (@ "network error: % d", iError );

}

}

-(Void) onGetPermissionState :( int) iError

{

If (iError = 0)

{

KHLog (@ "normal authorization ");

}

Else

{

KHLog (@ "authorization error: % d", iError );

}

}

-(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.

}

3. Add the proxy BMKMapViewDelegate to the controller to load the mapview.

Declare BMKMapView * _ mapView;

Note: # define _ SCREEN_SIZE [[UIScreen mainScreen] bounds]. size

-(Void) viewDidLoad {

[SuperviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

_ MapView = [[BMKMapView alloc] initWithFrame: CGRectMake (0, 0, _ SCREEN_SIZE.width, _ SCREEN_SIZE.height)];

[Self. view addSubview: _ mapView];

[_ MapViewsetMapType: BMKMapTypeStandard]; // map style

// [_ MapView setTrafficEnabled: YES]; // open the real-time traffic Layer

// [_ MapView setBaiduHeatMapEnabled: YES]; // open the Baidu city heat map layer (Baidu's own data)

}

-(Void) viewWillAppear :( BOOL) animated

{

[_ MapViewviewWillAppear];

_ MapView. delegate = self; // set nil when you do not need it here; otherwise, the memory will be released.

}

-(Void) viewWillDisappear :( BOOL) animated

{

[_ MapViewviewWillDisappear];

_ MapView. delegate = nil; // when not in use, set nil

}

-(Void) mapViewDidFinishLoading :( BMKMapView *) mapView

{

KHLog (@ "the map has been loaded"); // I will not show the proxy methods here. Please adjust the actual usage.

}

 

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.