Baidu Map iOS SDK is a set of application program interface based on iOS 5.0 and above, which not only provides the basic interface for displaying maps, but also provides rich LBS capabilities such as POI retrieval, path planning, map annotation, offline map, positioning, and peripheral radar.

The following interfaces are mainly introduced today

1. Basic map 2.POI retrieval 3

#### Configure the environment first

Development package in Framework form (using CocoaPods) < Recommended > 2. Manual configuration. Development package in framework form

#### special attention: ######(THERE are a lot of attention points in the API, we can go to see. However, one of the last two points I mentioned will fail. The first point is that if there is a need, it must be added.)

1, if in iOS9 used to tune up Baidu map client function, must be in"Info.plist"In the following configuration, otherwise baidu map client cannot be adjusted. < key > LSApplicationQueriesSchemes < / key > < array > < string > baidumap < / string > < / array > 2, since the iOS SDK v2.5.0 to's ability to locate iOS8 compatible, Need info. Add in the plist (the following a choice, both add default NSLocationWhenInUseUsageDescription) : NSLocationWhenInUseUsageDescription, allowing at the front desk when using GPS for describing NSLocationAlwaysUsageDescription, 3. During SDK development using Xcode6, add the following information to info.plist: Bundle display name, and its value cannot be empty (Xcode6 new projects do not have this configuration, otherwise will cause manager start failCopy the code

#### After the configuration is complete, initialize BMKMapManager in the appdelegate. m file and enter the requested authorization Key

#import "AppDelegate.h"
#import <BaiduMapAPI_Base/BMKMapManager.h>@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application LaunchOptions didFinishLaunchingWithOptions: (NSDictionary *) {/ / create and initialize an engine object BMKMapManager * manager = [[BMKMapManager alloc] init]; // Start map engine BOOL SUCCESS = [manager start:@"zBWLNgRUrTp9CVb5Ez6gZpNebljmYylO" generalDelegate:nil];
    
    if(! success) { NSLog(@"Failure");
    }
    // Override point for customization after application launch.
    return YES;
}
Copy the code

####1. Basic map

#import "ViewController.h"
#import <BaiduMapAPI_Map/BMKMapView.h>@interface ViewController ()<BMKMapViewDelegate> @property (nonatomic,strong) BMKMapView *mapView; @end@implementation ViewController - (void)viewDidLoad {[super viewDidLoad]; / / initialization map self. MapView = [[BMKMapView alloc] initWithFrame: self. The frame]; self.mapView.delegate =self; Self.mapview. mapType = BMKMapTypeSatellite; self.mapView.mapType = BMKMapTypeSatellite; / / satellite / / set the map is on the road layer self. The mapView. TrafficEnabled = YES; Self.mapview. showMapPoi = NO; Self.mapview. zoomLevel = 21; self.mapview. zoomLevel = 21; / / set the map View can support rotary self. The mapView. RotateEnabled = NO; / / set the map View can support the user mobile map self. The mapView. The scrollEnabled = NO; // Add to view [self.view addSubview:self.mapView]; // There are many more attributes, according to the requirements of the API}Copy the code

Operation effect into the bottom;

# # # # 2. Positioning

#import "ViewController.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
#import <BaiduMapAPI_Location/BMKLocationService.h>@interface ViewController ()<BMKLocationServiceDelegate,BMKMapViewDelegate> @property (nonatomic,strong) BMKMapView *mapView; // map view @property (nonatomic,strong) BMKLocationService *service; @implementation ViewController - (void)viewDidLoad {[super viewDidLoad]; / / initialization map self. MapView = [[BMKMapView alloc] initWithFrame: self. The frame]; self.mapView.delegate =self; // Add to view [self.view addSubview:self.mapView]; Self. service = [[BMKLocationService alloc] init]; // Set the delegate self.service.delegate = self; [self.service startUserLocationService]; // Do any additional setup after loading the view, typically from a nib. }#pragma mark -------BMKLocationServiceDelegate /** * After user location is updated, Will call this function * @ param userLocation new user location * / - (void) didUpdateBMKUserLocation: (userLocation BMKUserLocation *) {/ / show the positioning self.mapView.showsUserLocation = YES; / / update the location data [self. MapView updateLocationData: userLocation]; / / get the user the coordinates of the self. The mapView. CenterCoordinate = userLocation. Location. Coordinate; self.mapView.zoomLevel =18; }Copy the code

The results

# # # # POI retrieval

#import "ViewController.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
#import <BaiduMapAPI_Location/BMKLocationService.h>
#import <BaiduMapAPI_Search/BMKPoiSearch.h>
#import <BaiduMapAPI_Map/BMKAnnotation.h>
#import <BaiduMapAPI_Map/BMKPointAnnotation.h>
#import <BaiduMapAPI_Map/BMKPinAnnotationView.h>


#define kWidth [UIScreen mainScreen].bounds.size.width@interface ViewController ()<BMKLocationServiceDelegate,BMKPoiSearchDelegate,BMKMapViewDelegate> @property (nonatomic,strong) BMKMapView *mapView; // map view @property (nonatomic,strong) BMKLocationService *service; @property (nonatomic,strong) BMKPoiSearch *poiSearch; @property (nonatomic,strong) NSMutableArray *dataArray; @end @implementation ViewController - (NSMutableArray *)dataArray {if(! _dataArray) { _dataArray = [NSMutableArray array]; }return_dataArray; } - (void)viewDidLoad { [super viewDidLoad]; / / initialization map self. MapView = [[BMKMapView alloc] initWithFrame: self. The frame]; self.mapView.delegate =self; // // set the map display style // self.mapview. mapType = BMKMapTypeSatellite; Satellite images / / / / / / / / set the road / / self. The mapView. TrafficEnabled = YES; // self.mapview. showMapPoi = NO; // self.mapview. showMapPoi = NO; // // // Currently available level 3-21 on mobile // self.mapview.zoomlevel = 21; / / / / / / rotate / / self. The mapView. RotateEnabled = NO; / / / / / / drag / / self. The mapView. The scrollEnabled = NO; // [self.view addSubview:self.mapView]; Self. service = [[BMKLocationService alloc] init]; // Set the delegate self.service.delegate = self; [self.service startUserLocationService]; // Do any additional setup after loading the view, typically from a nib. }#pragma mark -------BMKLocationServiceDelegate /** * After user location is updated, Will call this function * @ param userLocation new user location * / - (void) didUpdateBMKUserLocation: (userLocation BMKUserLocation *) {/ / show the positioning self.mapView.showsUserLocation = YES; / / update the location data [self. MapView updateLocationData: userLocation]; / / get the user the coordinates of the self. The mapView. CenterCoordinate = userLocation. Location. Coordinate; self.mapView.zoomLevel =18; // Initialize the search self.poisearch =[[BMKPoiSearch alloc] init]; self.poiSearch.delegate = self; BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc] init]; // Index defaults to 0 option.pageIndex = 0; // The number of pages defaults to 10 option.pageCapacity = 50; // Search radius option.radius = 200; / / retrieval, the center of the longitude and latitude option. The location = userLocation. Location. Coordinate; // The search keyword option.keyword = @"Snack"; BOOL flag = [self.poiSearch poiSearchNearBy:option];if (flag) {
        NSLog(@"Search successful"); [self.service stopUserLocationService]; }else {
    
        NSLog(@"Search failed"); }}#pragma mark -------BMKPoiSearchDelegate/** * Return POI search results *@param searcher search object *@param poiResult List of search results *@param errorCode Error number, @see BMKSearchErrorCode */ - (void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPoiResult *)poiResult ErrorCode :(BMKSearchErrorCode)errorCode {// if the search succeedsif(errorCode ==BMK_SEARCH_NO_ERROR) {//POI information class //POI listfor (BMKPoiInfo *info inpoiResult.poiInfoList) { [self.dataArray addObject:info]; // Only three properties BMKPointAnnotation *annotoation = [[BMKPointAnnotation alloc] init]; // coordinate annotoation. Coordinate = info.pt; //title annotoation.title = info.name; // Annotoation. Subtitle = info.address; / / add annotation to the map [the self. The mapView addAnnotation: annotoation]; }} /** * Return POI details search result *@param searcher search object *@param poiDetailResult Details search result *@param errorCode Error number, @see BMKSearchErrorCode */ - (void)onGetPoiDetailResult:(BMKPoiSearch *)searcher result:(BMKPoiDetailResult *)poiDetailResult errorCode:(BMKSearchErrorCode)errorCode { NSLog(@"% @",poiDetailResult.name);
    
}


#pragma mark -------------BMKMapViewDelegate/** * The corresponding View *@param mapView *@param annotation is generated according to anntationreturnGenerated annotation View */ - (BMKAnnotationView *)mapView (BMKMapView *)mapView viewForAnnotation (id<BMKAnnotation>)annotation { // If it is a comment pointif([annotation isKindOfClass:[BMKPointAnnotation Class]]) {// Create and initialize the annotation point view BMKP based on the annotation pointinAnnotationView  *newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"an"]; // set the pinColor newAnnotation. PinColor = BMKPinAnnotationColorRed; / / set animation newAnnotation animatesDrop = YES;return newAnnotation;
        
    }

    returnnil; } /** * when an annotation view is selected, Call this interface *@param mapView mapView *@param views selected annotation views */ - (void)mapView:(BMKMapView *)mapView DidSelectAnnotationView :(BMKAnnotationView *)view {//poi details retrieve information class BMKPoiDetailSearchOption *option = [[BMKPoiDetailSearchOption alloc] init]; BMKPoiInfo *info = self.dataArray.firstObject; PoiUid = info.uid; // The uid of the poI is obtained from the BMKPoiResult structure returned by the POI. /** * Async function to retrieve poI details based on poI uid, Returns the result in the BMKPoiSearchDelegate onGetPoiDetailResult notification *@param Option POI detail retrieval parameter class (BMKPoiDetailSearchOption) *@returnReturn YES on success, or NO */ BOOL flag = [self.poisearch poiDetailSearch:option];if (flag) {
        NSLog(@"Retrieval successful");
    }
    else {
    
        NSLog(@"Retrieval failed"); }}Copy the code

The results

#### summary Baidu map function is very powerful, there are a lot of retrieval, are not written. You can also be interested in delving into the next, after all, the third-party interface documentation is relatively clear. If you have any questions, leave a message