重要:为进一步采取加强对最终用户个人信息的安全保护措施,从定位sdk v2.0.2版本起,请开发者务必确保调用sdk任何接口前先调用隐私合规接口setagreeprivacy,否则可能会无法正常使用相关功能。具体可参考开发指南-注册和获取秘钥-ios定位sdk隐私合规接口。
百度地图ios定位sdk以ios系统定位能力为基础,在此基础之上,面向广大开发者提供了更多丰富功能,包括:地址解析、位置描述、移动热点识别、地理围栏、国内外位置判断等功能。
ios定位sdk已适配ios 16,开发者可放心使用。
ios定位sdk在ios14及之后对系统新推出的定位精度等级功能进行了适配,开发者可参照开发文档进行集成。
#import<bmklocationkit/bmklocationcomponent.h>-(bool)application:(uiapplication*)application didfinishlaunchingwithoptions:(nsdictionary*)launchoptions {// 需要注意的是请在 sdk 任何类的初始化以及方法调用之前设置正确的 ak[[bmklocationauth sharedinstance] checkpermisionwithkey:@"您的ak"authdelegate:self];returnyes;}bmklocationmanager*locationmanager =[[bmklocationmanager alloc] init];locationmanager.delegate= self;locationmanager.coordinatetype=bmklocationcoordinatetypebmk09ll;locationmanager.distancefilter= kcldistancefilternone;locationmanager.desiredaccuracy= kcllocationaccuracybest;locationmanager.activitytype=clactivitytypeautomotivenavigation;locationmanager.pauseslocationupdatesautomatically=no;locationmanager.allowsbackgroundlocationupdates=yes;locationmanager.locationtimeout=10;locationmanager.regeocodetimeout=10;[locationmanager requestlocationwithregeocode:yeswithnetworkstate:yescompletionblock:^(bmklocation* _nullable location,bmklocationnetworkstate state,nserror* _nullable error){//获取经纬度和该定位点对应的位置信息}];
#import<bmklocationkit/bmklocationcomponent.h>-(bool)application:(uiapplication*)application didfinishlaunchingwithoptions:(nsdictionary*)launchoptions {// 需要注意的是请在 sdk 任何类的初始化以及方法调用之前设置正确的 ak[[bmklocationauth sharedinstance] checkpermisionwithkey:@"您的ak"authdelegate:self];returnyes;}bmklocationmanager*locationmanager =[[bmklocationmanager alloc] init];locationmanager.delegate= self;locationmanager.coordinatetype=bmklocationcoordinatetypebmk09ll;locationmanager.distancefilter= kcllocationaccuracybestfornavigation;locationmanager.desiredaccuracy= kcllocationaccuracybest;locationmanager.activitytype=clactivitytypeautomotivenavigation;locationmanager.pauseslocationupdatesautomatically=no;locationmanager.allowsbackgroundlocationupdates=no;// yes的话是可以进行后台定位的,但需要项目配置,否则会报错,具体参考开发文档locationmanager.locationtimeout=10;locationmanager.regeocodetimeout=10;//开始定位[locationmanager startupdatinglocation];//结束定位//[locationmanager stopupdatinglocation];#pragma mark -bmklocationmanagerdelegate/*** @brief 连续定位回调函数。* @param manager 定位 bmklocationmanager 类。* @param location 定位结果,参考bmklocation。* @param error 错误信息。*/-(void)bmklocationmanager:(bmklocationmanager* _nonnull)manager didupdatelocation:(bmklocation* _nullable)location orerror:(nserror* _nullable)error{}/*** @brief 该方法为bmklocationmanager提供设备朝向的回调方法。* @param manager 提供该定位结果的bmklocationmanager类的实例* @param heading 设备的朝向结果*/-(void)bmklocationmanager:(bmklocationmanager* _nonnull)managerdidupdateheading:(clheading* _nullable)heading{}
#import<bmklocationkit/bmklocationcomponent.h>-(bool)application:(uiapplication*)application didfinishlaunchingwithoptions:(nsdictionary*)launchoptions {// 需要注意的是请在 sdk 任何类的初始化以及方法调用之前设置正确的 ak[[bmklocationauth sharedinstance] checkpermisionwithkey:@"您的ak"authdelegate:self];returnyes;}bmklocationmanager*locationmanager =[[bmklocationmanager alloc] init];locationmanager.delegate= self;locationmanager.coordinatetype=bmklocationcoordinatetypebmk09ll;locationmanager.distancefilter= kcllocationaccuracybestfornavigation;locationmanager.desiredaccuracy= kcllocationaccuracybest;locationmanager.activitytype=clactivitytypeautomotivenavigation;locationmanager.pauseslocationupdatesautomatically=no;locationmanager.allowsbackgroundlocationupdates=yes;// yes的话是可以进行后台定位的,但需要项目配置,否则会报错,具体参考开发文档locationmanager.locationtimeout=10;locationmanager.regeocodetimeout=10;//开始定位[locationmanager startupdatinglocation];//结束定位//[locationmanager stopupdatinglocation];#pragma mark -bmklocationmanagerdelegate/*** @brief 连续定位回调函数。* @param manager 定位 bmklocationmanager 类。* @param location 定位结果,参考bmklocation。* @param error 错误信息。*/-(void)bmklocationmanager:(bmklocationmanager* _nonnull)manager didupdatelocation:(bmklocation* _nullable)location orerror:(nserror* _nullable)error{}/*** @brief 该方法为bmklocationmanager提供设备朝向的回调方法。* @param manager 提供该定位结果的bmklocationmanager类的实例* @param heading 设备的朝向结果*/-(void)bmklocationmanager:(bmklocationmanager* _nonnull)managerdidupdateheading:(clheading* _nullable)heading{}
#import<bmklocationkit/bmklocationcomponent.h>-(bool)application:(uiapplication*)application didfinishlaunchingwithoptions:(nsdictionary*)launchoptions {// 需要注意的是请在 sdk 任何类的初始化以及方法调用之前设置正确的 ak[[bmklocationauth sharedinstance] checkpermisionwithkey:@"您的ak"authdelegate:self];returnyes;}bmklocationmanager*locationmanager =[[bmklocationmanager alloc] init];locationmanager.delegate= self;locationmanager.coordinatetype=bmklocationcoordinatetypebmk09ll;locationmanager.distancefilter= kcldistancefilternone;locationmanager.desiredaccuracy= kcllocationaccuracybest;locationmanager.activitytype=clactivitytypeautomotivenavigation;locationmanager.pauseslocationupdatesautomatically=no;locationmanager.allowsbackgroundlocationupdates=yes;locationmanager.locationtimeout=10;locationmanager.regeocodetimeout=10;[locationmanager requestlocationwithregeocode:yeswithnetworkstate:yescompletionblock:^(bmklocation* _nullable location,bmklocationnetworkstate state,nserror* _nullable error){}];
#import<bmklocationkit/bmklocationcomponent.h>-(bool)application:(uiapplication*)application didfinishlaunchingwithoptions:(nsdictionary*)launchoptions {// 需要注意的是请在 sdk 任何类的初始化以及方法调用之前设置正确的 ak[[bmklocationauth sharedinstance] checkpermisionwithkey:@"您的ak"authdelegate:self];returnyes;}#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];bmkgeofencemanager*geofencemanager =[[bmkgeofencemanager alloc] init];geofencemanager.delegate= self;geofencemanager.pauseslocationupdatesautomatically=no;geofencemanager.allowsbackgroundlocationupdates=yes;cllocationcoordinate2d centergeofence =cllocationcoordinate2dmake(39.914682,116.403898);//天安门bmkpointannotation*pointannotation =[[bmkpointannotation alloc]init];pointannotation.coordinate= centergeofence;pointannotation.title= @"圆形地理围栏";[mapview removeannotations:mapview.annotations];[mapview addannotation:pointannotation];bmkcircle* circle =[bmkcircle circlewithcentercoordinate:_ centergeofence radius:100];[mapview addoverlay:circle];geofencemanager.activeaction=bmkgeofenceactiveactionstayed|bmkgeofenceactiveactioninside|bmkgeofenceactiveactionoutside;[geofencemanager addcircleregionformonitoringwithcenter:centergeofence radius:100coortype:bmklocationcoordinatetypebmk09ll customid:@"circle_1"];#pragma mark -bmkmapviewdelegate/***根据anntation生成对应的view*@param mapview 地图view*@param annotation 指定的标注*@return 生成的标注view*/-(bmkannotationview*)mapview:(bmkmapview*)mapview viewforannotation:(id <bmkannotation>)annotation{//普通annotationnsstring*annotationviewid= @"renamemark";bmkpinannotationview*annotationview =(bmkpinannotationview*)[mapview dequeuereusableannotationviewwithidentifier:annotationviewid];if(annotationview == nil){annotationview =[[bmkpinannotationview alloc] initwithannotation:annotation reuseidentifier:annotationviewid];// 设置颜色annotationview.pincolor=bmkpinannotationcolorpurple;// 从天上掉下效果annotationview.animatesdrop=yes;// 设置可拖拽annotationview.draggable=yes;}return annotationview;}/***根据overlay生成对应的view*@param mapview 地图view*@param overlay 指定的overlay*@return 生成的覆盖物view*/-(bmkoverlayview*)mapview:(bmkmapview*)mapview viewforoverlay:(id <bmkoverlay>)overlay{if([overlay iskindofclass:[bmkcircleclass]]){bmkcircleview* circleview =[[bmkcircleview alloc] initwithoverlay:overlay];circleview.fillcolor=[[uicolor alloc] initwithred:1green:0blue:0alpha:0.1];circleview.strokecolor=[[uicolor alloc] initwithred:0green:0blue:1alpha:0.5];circleview.linewidth=2.0;return circleview;}return nil;}
百度地图ios定位sdk对非商业目的的开发者是不收取任何费用的,接口使用无次数限制。
如您以商业目的(包括但不限于对第三方用户收费、项目投标,以及其他直接或间接获取收益或利益)使用本平台服务,则用户须要事先获得本平台"商用授权"许可。 平台商用授权的授权对象为公司主体。授权成功后,您将会收到平台提供的书面版商用授权书(附带百度公司签章)。
商业目的产品使用前请参考使用须知。
在您使用百度地图ios定位sdk之前,请先阅读并同意百度地图开放平台服务条款中的各项内容,并申请申请密钥(ak)才可使用。
下一篇
本篇文章对您是否有帮助?