重要:为进一步采取加强对最终用户个人信息的安全保护措施,从地图SDK v6.5.1版本起,请开发者务必确保调用SDK任何接口前先调用隐私合规接口setAgreePrivacy,否则可能会无法正常使用相关功能。具体可参考开发指南-开发注意事项-隐私政策接口说明。
#import <BaiduMapAPI_Base/BMKBaseComponent.h>#import <BaiduMapAPI_Map/BMKMapComponent.h>//当前界面的mapView@property (nonatomic, strong) BMKMapView *mapView;- (void)viewDidLoad {[super viewDidLoad];_mapView = [[BMKMapView alloc] initWithFrame:self.view.bounds];//设置mapView的代理_mapView.delegate = self;//将mapView添加到当前视图中[self.view addSubview:_mapView];}- (void)viewWillAppear:(BOOL)animated {[super viewWillAppear: animated];//当mapView即将被显示的时候调用,恢复之前存储的mapView状态[_mapView viewWillAppear];}- (void)viewWillDisappear:(BOOL)animated {[super viewWillDisappear: animated];//当mapView即将被隐藏的时候调用,存储当前mapView的状态[_mapView viewWillDisappear];}
#import <BaiduMapAPI_Base/BMKBaseComponent.h>#import <BaiduMapAPI_Map/BMKMapComponent.h>BMKMapView *mapView = [[BMKMapView alloc] initWithFrame:self.view.bounds];//设置mapView的代理mapView.delegate = self;//将mapView添加到当前视图中[self.view addSubview:mapView];//设置当前地图的中心点,改变该值时,地图的比例尺级别不会发生变化mapView.centerCoordinate = CLLocationCoordinate2DMake(39.917, 116.379);//设置地图比例尺级别mapView.zoomLevel = 18;mapView.baseIndoorMapEnabled = YES;mapView.showIndoorMapPoi = YES;#pragma mark - BMKMapViewDelegate/***地图进入/移出室内图会调用此接口*@param mapView 地图View*@param flag YES:进入室内图; NO:移出室内图*@param info 室内图信息*/-(void)mapview:(BMKMapView *)mapView baseIndoorMapWithIn:(BOOL)flag baseIndoorMapInfo:(BMKBaseIndoorMapInfo *)info{if (flag) {//进入室内图} else {//移出室内图}}
#import <BaiduMapAPI_Base/BMKBaseComponent.h>#import <BaiduMapAPI_Map/BMKMapComponent.h>BMKMapView *mapView = [[BMKMapView alloc] initWithFrame:self.view.bounds];//设置mapView的代理mapView.delegate = self;//将mapView添加到当前视图中[self.view addSubview:mapView];BMKMapStatus *status = [[BMKMapStatus alloc]init];status.fLevel = 10;status.targetGeoPt = CLLocationCoordinate2DMake(51.50556,-0.07556);[mapView setMapStatus:status withAnimation:YES withAnimationTime:1000];
#import <BaiduMapAPI_Base/BMKBaseComponent.h>#import <BaiduMapAPI_Map/BMKMapComponent.h>- (void)viewDidLoad {[super viewDidLoad];BMKMapView *mapView = [[BMKMapView alloc] initWithFrame:self.view.bounds];//设置mapView的代理mapView.delegate = self;//将mapView添加到当前视图中[self.view addSubview:mapView];//初始化标注类BMKPointAnnotation的实例BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc] init];//设置标注的经纬度坐标annotation.coordinate = CLLocationCoordinate2DMake(39.915, 116.404);//设置标注的标题annotation.title = @"标注";//副标题annotation.subtitle = @"可拖拽";/**当前地图添加标注,需要实现BMKMapViewDelegate的-mapView:viewForAnnotation:方法来生成标注对应的View@param annotation 要添加的标注*/[mapView addAnnotation:annotation];}#pragma mark - BMKMapViewDelegate/**根据anntation生成对应的annotationView@param mapView 地图View@param annotation 指定的标注@return 生成的标注View*/- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation {if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {/**根据指定标识查找一个可被复用的标注,用此方法来代替新创建一个标注,返回可被复用的标注*/BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"annotationViewIdentifier"];if (!annotationView) {/**初始化并返回一个annotationView@param annotation 关联的annotation对象@param reuseIdentifier 如果要重用view,传入一个字符串,否则设为nil,建议重用view@return 初始化成功则返回annotationView,否则返回nil*/annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotationViewIdentifier"];//annotationView显示的图片,默认是大头针//annotationView.image = nil;/**默认情况下annotationView的中心点位于annotation的坐标位置,可以设置centerOffset改变annotationView的位置,正的偏移使annotationView朝右下方移动,负的朝左上方,单位是像素*/annotationView.centerOffset = CGPointMake(0, 0);/**默认情况下, 弹出的气泡位于annotationView正中上方,可以设置calloutOffset改变annotationView的位置,正的偏移使annotationView朝右下方移动,负的朝左上方,单位是像素*/annotationView.calloutOffset = CGPointMake(0, 0);//是否显示3D效果,标注在地图旋转和俯视时跟随旋转、俯视,默认为NOannotationView.enabled3D = NO;//是否忽略触摸时间,默认为YESannotationView.enabled = YES;/**开发者不要直接设置这个属性,若设置,需要在设置后调用BMKMapView的-(void)mapForceRefresh;方法刷新地图,默认为NO,当annotationView被选中时为YES*/annotationView.selected = NO;//annotationView被选中时,是否显示气泡(若显示,annotation必须设置了title),默认为YESannotationView.canShowCallout = YES;/**显示在气泡左侧的view(使用默认气泡时,view的width最大值为32,height最大值为41,大于则使用最大值)*/annotationView.leftCalloutAccessoryView = nil;/**显示在气泡右侧的view(使用默认气泡时,view的width最大值为32,height最大值为41,大于则使用最大值)*/annotationView.rightCalloutAccessoryView = nil;/**annotationView的颜色: BMKPinAnnotationColorRed,BMKPinAnnotationColorGreen,BMKPinAnnotationColorPurple*/annotationView.pinColor = BMKPinAnnotationColorRed;//设置从天而降的动画效果annotationView.animatesDrop = YES;//当设为YES并实现了setCoordinate:方法时,支持将annotationView在地图上拖动annotationView.draggable = YES;//当前view的拖动状态//annotationView.dragState;}return annotationView;}return nil;}
#import <BaiduMapAPI_Base/BMKBaseComponent.h>#import <BaiduMapAPI_Search/BMKSearchComponent.h>BMKSuggestionSearch *suggestionSearch = [[BMKSuggestionSearch alloc]init];suggestionSearch.delegate = self;BMKSuggestionSearchOption* suggestionOption = [[BMKSuggestionSearchOption alloc] init];suggestionOption.keyword = @"麦当劳";suggestionOption.cityname = @"北京";suggestionOption.cityLimit = NO;/**关键词检索,异步方法,返回结果在BMKSuggestionSearchDelegate的onGetSuggestionResult里suggestionOption sug检索信息类成功返回YES,否则返回NO*/BOOL flag = [suggestionSearch suggestionSearch:suggestionOption];if(flag) {NSLog(@"关键词检索成功");} else {NSLog(@"关键词检索失败");}#pragma mark - BMKSuggestionSearchDelegate/**关键字检索结果回调@param searcher 检索对象@param result 关键字检索结果@param error 错误码,@see BMKCloudErrorCode*/- (void)onGetSuggestionResult:(BMKSuggestionSearch *)searcher result:(BMKSuggestionSearchResult *)result errorCode:(BMKSearchErrorCode)error {//BMKSearchErrorCode错误码,BMK_SEARCH_NO_ERROR:检索结果正常返回if (error == BMK_SEARCH_NO_ERROR) {//实现对检索结果的处理}}//初始化BMKPoiSearch实例BMKPoiSearch *poiSearch = [[BMKPoiSearch alloc] init];//设置POI检索的代理poiSearch.delegate = self;//初始化请求参数类BMKNearbySearchOption的实例BMKPOINearbySearchOption *nearbyOption = [[BMKPOINearbySearchOption alloc]init];/**检索关键字,必选。在周边检索中关键字为数组类型,可以支持多个关键字并集检索,如银行和酒店。每个关键字对应数组一个元素。最多支持10个关键字。*/nearbyOption.keywords = @[@"麦当劳"];//检索中心点的经纬度,必选nearbyOption.location = CLLocationCoordinate2DMake(40.056974, 116.307689);/**检索半径,单位是米。当半径过大,超过中心点所在城市边界时,会变为城市范围检索,检索范围为中心点所在城市*/nearbyOption.radius = 1000;/**根据中心点、半径和检索词发起周边检索:异步方法,返回结果在BMKPoiSearchDelegate的onGetPoiResult里nearbyOption 周边搜索的搜索参数类成功返回YES,否则返回NO*/BOOL flag = [poiSearch poiSearchNearBy:nearbyOption];if(flag) {NSLog(@"POI周边检索成功");} else {NSLog(@"POI周边检索失败");}#pragma mark - BMKPoiSearchDelegate/**POI检索返回结果回调@param searcher 检索对象@param poiResult POI检索结果列表@param error 错误码*/- (void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPOISearchResult *)poiResult errorCode:(BMKSearchErrorCode)error {//BMKSearchErrorCode错误码,BMK_SEARCH_NO_ERROR:检索结果正常返回if (error == BMK_SEARCH_NO_ERROR) {//实现对检索结果的处理}}
#import <BaiduMapAPI_Base/BMKBaseComponent.h>#import <BaiduMapAPI_Search/BMKSearchComponent.h>//初始化BMKRouteSearch实例BMKRouteSearch *drivingRouteSearch = [[BMKRouteSearch alloc]init];//设置驾车路径的规划drivingRouteSearch.delegate = self;BMKDrivingRoutePlanOption *drivingRoutePlanOption = [[BMKDrivingRoutePlanOption alloc] init];//实例化线路检索节点信息类对象BMKPlanNode *start = [[BMKPlanNode alloc]init];//起点名称start.name = @"天安门";//起点所在城市start.cityName = @"北京";//实例化线路检索节点信息类对象BMKPlanNode *end = [[BMKPlanNode alloc]init];//终点名称end.name = @"百度科技园";//终点所在城市end.cityName = @"北京市";//检索的起点,可通过关键字、坐标两种方式指定。cityName和cityID同时指定时,优先使用cityIDdrivingRoutePlanOption.from = start;//检索的终点,可通过关键字、坐标两种方式指定。cityName和cityID同时指定时,优先使用cityIDdrivingRoutePlanOption.to = end;NSMutableArray * wayPointsArray = [[NSMutableArray alloc] initWithCapacity:1];BMKPlanNode* wayPointItem = [[BMKPlanNode alloc]init];wayPointItem.cityName = @"北京市";wayPointItem.name = @"西二旗地铁站";[wayPointsArray addObject:wayPointItem];drivingRoutePlanOption.wayPointsArray = wayPointsArray;/**发起驾乘路线检索请求,异步函数,返回结果在BMKRouteSearchDelegate的onGetDrivingRouteResult中*/BOOL flag = [drivingRouteSearch drivingSearch: drivingRoutePlanOption];if(flag) {NSLog(@"驾车检索成功");} else {NSLog(@"驾车检索失败");}#pragma mark - BMKRouteSearchDelegate/***返回驾乘搜索结果*@param searcher 搜索对象*@param result 搜索结果,类型为BMKDrivingRouteResult*@param error 错误号,@see BMKSearchErrorCode*/- (void)onGetDrivingRouteResult:(BMKRouteSearch*)searcher result:(BMKDrivingRouteResult*)result errorCode:(BMKSearchErrorCode)error{//BMKSearchErrorCode错误码,BMK_SEARCH_NO_ERROR:检索结果正常返回if (error == BMK_SEARCH_NO_ERROR) {//实现对检索结果的处理}}
#import <BaiduMapAPI_Map_For_WalkNavi/BMKMapComponent.h>#import <BaiduMapAPI_WalkNavi/BMKWalkNaviComponent.h>@property (nonatomic, strong) BMKWalkNaviViewController *controller; ///导航页面_controller = [[BMKWalkNaviViewController alloc] init];BOOL inited = [[BMKWalkNavigationManager sharedManager] initNaviEngine:_controller];[BMKWalkNavigationManager sharedManager].routePlanDelegate = self;[BMKWalkNavigationManager sharedManager].routeGuidanceDelegate = self;[BMKWalkNavigationManager sharedManager].ttsPlayerDelegate = self;if (inited) {NSLog(@"SDK-初始化引擎成功");BMKWalkNaviLaunchParam *param = [[BMKWalkNaviLaunchParam alloc] init];param.startPoint = CLLocationCoordinate2DMake(40.049879,116.279853);//起点坐标,百度科技园;param.endPoint = CLLocationCoordinate2DMake(40.058918,116.312621); //终点坐标,西二旗地铁站;[[BMKWalkNavigationManager sharedManager] routePlanWithParams:param];}#pragma mark - BMKWalkCycleRoutePlanDelegate/**开始算路*/- (void)onRoutePlanStart:(BMKWalkCycleNavigationType)naviType {NSLog(@"SDK-开始算路");}- (void)onRoutePlanResult:(BMKWalkCycleRoutePlanErrorCode)errorCode naviType:(BMKWalkCycleNavigationType)naviType{if (errorCode == BMK_WALK_CYCLE_ROUTEPLAN_RESULT_SUCCESS) {NSLog(@"SDK-算路成功");_controller.navigationType = 0;[self.navigationController pushViewController:_controller animated:YES];} else {NSLog(@"SDK-算路失败");}}//BMKWalkNaviViewController- (void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];self.navigationController.navigationBarHidden = YES;[[BMKWalkNavigationManager sharedManager] resume];[[BMKWalkNavigationManager sharedManager] startWalkNavi:BMK_WALK_NAVIGATION_MODE_WALK_NORMAL];//BMK_WALK_NAVIGATION_MODE_WALK_AR}- (void)viewWillDisappear:(BOOL)animated {[super viewWillDisappear:animated];self.navigationController.navigationBarHidden = NO;[BMKWalkNavigationManager destroy];}
//BMKWalkRoutePlanController#import <BaiduMapAPI_Map_For_WalkNavi/BMKMapComponent.h>#import <BaiduMapAPI_WalkNavi/BMKWalkNaviComponent.h>@property (nonatomic, strong) BMKWalkNaviViewController *controller; ///导航页面BMKWalkCycleNavigationDisplayOption *naviOption = [[BMKWalkCycleNavigationDisplayOption alloc] init];_controller = [[BMKWalkNaviViewController alloc] init];BOOL inited = [[BMKCycleNavigationManager sharedManager] initNaviEngine:_controller option:naviOption];[BMKCycleNavigationManager sharedManager].routePlanDelegate = self;[BMKCycleNavigationManager sharedManager].routeGuidanceDelegate = self;[BMKCycleNavigationManager sharedManager].ttsPlayerDelegate = self;if (inited) {NSLog(@"SDK-初始化引擎成功");BMKCycleNaviLaunchParam *param = [[BMKCycleNaviLaunchParam alloc] init];param.startPoint = CLLocationCoordinate2DMake(40.049879,116.279853);//起点坐标,百度科技园;param.endPoint = CLLocationCoordinate2DMake(40.058918,116.312621); //终点坐标,西二旗地铁站;param.naviType = BMK_WALK_CYCLE_NAVIGATION_TYPE_ELECTRIC_CYCLE;[[BMKCycleNavigationManager sharedManager] routePlanWithParams:param];}#pragma mark - BMKWalkCycleRoutePlanDelegate/**开始算路*/- (void)onRoutePlanStart:(BMKWalkCycleNavigationType)naviType {NSLog(@"SDK-开始算路");}- (void)onRoutePlanResult:(BMKWalkCycleRoutePlanErrorCode)errorCode naviType:(BMKWalkCycleNavigationType)naviType{if (errorCode == BMK_WALK_CYCLE_ROUTEPLAN_RESULT_SUCCESS) {NSLog(@"SDK-算路成功");_controller.navigationType = 1;[self.navigationController pushViewController:_controller animated:YES];} else {NSLog(@"SDK-算路失败");}}//BMKWalkNaviViewController- (void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];self.navigationController.navigationBarHidden = YES;[[BMKCycleNavigationManager sharedManager] resume];[[BMKCycleNavigationManager sharedManager] startCycleNavi];}- (void)viewWillDisappear:(BOOL)animated {[super viewWillDisappear:animated];self.navigationController.navigationBarHidden = NO;[BMKCycleNavigationManager destroy];}
下一篇
本篇文章对您是否有帮助?