1.使用pod获取百度地图SDK:
pod 'BaiduMapKit'
pod install
2.修改AppDelegate.m 为AppDelegate.mm,在AppDelegate.mm文件中配置key:
/**配置百度地图 需引入头文件(<BaiduMapAPI_Map/BMKMapComponent.h>)*/
BMKMapManager *manager = [[BMKMapManager alloc]init];
BOOL ret = [manager start:@"QyyYNtdIRObLlCduZjBY7N2RkOOCcqPC" generalDelegate:self];
if (!ret) {
NSLog(@"百度地图开启失败");
}
3.创建BaiduMapViewController控制器:
#import "BaiduMapViewController.h"
@interface BaiduMapViewController ()<BMKMapViewDelegate,BMKLocationServiceDelegate,UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource,BMKPoiSearchDelegate,BMKGeoCodeSearchDelegate>
/**地图 需引入头文件(<BaiduMapAPI_Map/BMKMapView.h>)*/
@property (nonatomic, strong)BMKMapView *mapView;
/**用户定位*/
@property (nonatomic, strong)BMKUserLocation *userLocation;
/**定位服务 需引入头文件(<BaiduMapAPI_Location/BMKLocationComponent.h>)*/
@property (nonatomic, strong)BMKLocationService *locationService;
/**POI搜索服务 需引入头文件(<BaiduMapAPI_Search/BMKPoiSearch.h>)*/
@property (nonatomic, strong)BMKPoiSearch *search;
/**地理搜索 需要引入头文件<BaiduMapAPI_Search/BMKGeocodeSearch.h>*/
@property (nonatomic, strong)BMKGeoCodeSearch *geoSearch;
/**搜索输入框*/
@property (nonatomic, strong)UITextField *textF;
@property (nonatomic, strong)UITableView *tab;
@property (nonatomic, strong)NSArray *results;
@end
@implementation BaiduMapViewController
- (void)viewWillAppear:(BOO