重要:为进一步采取加强对最终用户个人信息的安全保护措施,从地图sdk v6.5.1版本起,请开发者务必确保调用sdk任何接口前先调用隐私合规接口setagreeprivacy,否则可能会无法正常使用相关功能。具体可参考开发指南-开发注意事项-隐私政策接口说明。
ios地图sdk可用于ios原生开发,支持地图展示(室内图、室外图)、地图交互、在地图上绘制、检索地图数据等功能。地图sdk提供丰富的点线面和模型绘制能力,满足各类业务场景的个性化需求。
#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 {[superviewwillappear: animated];//当mapview即将被显示的时候调用,恢复之前存储的mapview状态[_mapview viewwillappear];}-(void)viewwilldisappear:(bool)animated {[superviewwilldisappear: 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:yeswithanimationtime: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:[bmkpointannotationclass]]){/**根据指定标识查找一个可被复用的标注,用此方法来代替新创建一个标注,返回可被复用的标注*/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 {[superviewwillappear: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 {[superviewwilldisappear: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 {[superviewwillappear:animated];self.navigationcontroller.navigationbarhidden=yes;[[bmkcyclenavigationmanager sharedmanager] resume];[[bmkcyclenavigationmanager sharedmanager] startcyclenavi];}-(void)viewwilldisappear:(bool)animated {[superviewwilldisappear:animated];self.navigationcontroller.navigationbarhidden=no;[bmkcyclenavigationmanager destroy];}
在您使用百度ios地图sdk之前,请先阅读并同意百度地图开放平台服务条款中的各项内容,并申请密钥(ak)才可使用。
您在使用中遇到任何问题,都可以通过反馈给我们,之后会有凯发k8官方旗舰厅的技术支持人员一对一为您处理问题。
目前百度地图ios地图sdk境内服务对非商业目的使用的开发者不收取任何费用,开发者可自行下载放心使用。
如您以商业目的(包括但不限于对第三方用户收费、项目投标,以及其他直接或间接获取收益或利益)使用本平台服务,则用户须要事先获得本平台"商用授权"许可。 平台商用授权的授权对象为公司主体。授权成功后,您将会收到平台提供的书面版商用授权书(附带百度公司签章)。
商用授权可点击这里了解详情。商业目的产品使用前请参考使用须知。
下一篇
本篇文章对您是否有帮助?