iOS开发(第三方使用)——百度地图鹰眼轨迹SDK接入
2016-06-13 19:50
781 查看
iOS开发交流群:301058503
在buidsettings输入bite,选择Enable bite code,值为NO;
在plist添加NSLocationAlwaysUsageDescription
。。。
使用
—1—
—2—开启服务
—3—收集轨迹
—4—结束
—5—查询轨迹
登录百度地图开放平台,找到iOS的鹰眼轨迹的SDK,下载,然后把BaiduTraceSDK.framework导入工程(选择工程->General ,把SDK拖到Embedded Baniaries)
设置头文件路径(选择刚刚导入的SDK,Show in Finder,选择工程->Build Settings ,搜索框输入search,找到Header Serach Paths ,双击这行的右边,弹出一个大的输入框,把刚才Show in Finder的文件夹里面的Headers文件夹直接拖到大输入框里)
导入类库CoreLocation.framework,QuartzCore.framework,OpenGLES.framework,
SystemConfiguration.framework,CoreGraphics.framework,
Security.framework,libsqlite3.0.tbd,CoreTelephony.framework,libstdc++.6.0.9.tbd
….
解决 230 image not found 的问题(有时候工程无缘无故地在还没有进入的时候就崩了,很可能也是这里的问题,有一次我明明之前已经设置好了,没动过它,它也会自动地变成了NO,坑了好久)注意:Xcode 8 把这项改了名字:Always Embed Swift Standard Libraries
添加Bundle display name,并且在使用到百度SDK的文件中,把文件.m后缀改为.mm
允许https(在plist添加NSAppTransportSecurity,类型Dictionary ,在此目录下添加NSAllowsArbitraryLoads,类型boolean,值为YES;)
在buidsettings输入bite,选择Enable bite code,值为NO;
在plist添加NSLocationAlwaysUsageDescription
在工程的AppDelegate.h
在工程的AppDelegate.m
13.在需要用到的控制器里
注意:1.bundle id ,工程里的mode,和百度开发者中心的安全码要保持一致,否则会出现只有白色网格的情况。
2. “230 image not found” Build Settings->Build Options->Always Embed Swift Standard Libraries->YES
3. “指定track不存在” 去到百度开发者官网的service_id那里,点击相应的ID的项目,创建一个entityName,或者选择某个entityName(如果有的话)去替换你工程里的 entityName
4. 更多未知问题请去官网论坛查看,有时候可能是因为官网未能及时更新,所以看看官网公告
iOS开发交流群:301058503
>=3.0版本的接入(适配XCode8.3以上)
登录百度地图开放平台,找到iOS的鹰眼轨迹的SDK,下载,然后把BaiduTraceSDK.framework导入工程(选择工程->General ,把SDK拖到Embedded Baniaries)在buidsettings输入bite,选择Enable bite code,值为NO;
在plist添加NSLocationAlwaysUsageDescription
。。。
使用
—1—
#import "BaiduTraceSDK/BaiduTraceSDK.h" 添加代理BTKTraceDelegate, BTKFenceDelegate, BTKTrackDelegate, BTKEntityDelegate
- (void)viewDidLoad { [super viewDidLoad]; // 使用SDK的任何功能前,都需要先调用initInfo:方法设置基础信息。 BTKServiceOption *sop = [[BTKServiceOption alloc] initWithAK:AK mcode:mcode serviceID:serviceID keepAlive:false]; [[BTKAction sharedInstance] initInfo:sop]; }
—2—开启服务
BTKStartServiceOption *op = [[BTKStartServiceOption alloc] initWithEntityName:entityName]; [[BTKAction sharedInstance] startService:op delegate:self]; 服务回调 -(void)onStartService:(BTKServiceErrorCode)error { NSLog(@"start service response: %lu", (unsigned long)error);//0成功 }
—3—收集轨迹
[[BTKAction sharedInstance] startGather:self]; 回调 -(void)onStartGather:(BTKGatherErrorCode)error { NSLog(@"start gather response: %lu", (unsigned long)error);//0成功,正在收集轨迹 }
—4—结束
[[BTKAction sharedInstance] stopGather:self]; 回调 -(void)onStopGather:(BTKGatherErrorCode)error { NSLog(@"stop gather response: %lu", (unsigned long)error);//6成功结束 }
—5—查询轨迹
NSUInteger endTime = [[NSDate date] timeIntervalSince1970]; BTKQueryTrackProcessOption *option = [[BTKQueryTrackProcessOption alloc] init]; option.denoise = FALSE; option.vacuate = FALSE;//抽稀属性只有查询历史轨迹时才有作用 option.mapMatch = FALSE; option.radiusThreshold = 55; BTKQueryHistoryTrackRequest *request = [[BTKQueryHistoryTrackRequest alloc] initWithEntityName:entityName startTime:endTime - 84400 endTime:endTime isProcessed:TRUE processOption:option supplementMode:BTK_TRACK_PROCESS_OPTION_SUPPLEMENT_MODE_DRIVING outputCoordType:BTK_COORDTYPE_BD09LL sortType:BTK_TRACK_SORT_TYPE_ASC pageIndex:1 pageSize:100 serviceID:serviceID tag:13]; [[BTKTrackAction sharedInstance] queryHistoryTrackWith:request delegate:self]; 回调 -(void)onQueryHistoryTrack:(NSData *)response { //轨迹数据 NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:nil]; NSLog(@"track history response: %@", dict); //数据处理 } //显示轨迹的回调 -(BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay { if ([overlay isKindOfClass:[BMKPolyline class]]) { BMKPolylineView* polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay]; polylineView.strokeColor = [[UIColor purpleColor] colorWithAlphaComponent:1]; polylineView.lineWidth = 5.0; return polylineView; } return nil; }
<3.0版本以下的接入(XCode8.2以下)
使用cocoapods导入百度地图的基础的SDK: pod ‘BaiduMapKit’登录百度地图开放平台,找到iOS的鹰眼轨迹的SDK,下载,然后把BaiduTraceSDK.framework导入工程(选择工程->General ,把SDK拖到Embedded Baniaries)
设置头文件路径(选择刚刚导入的SDK,Show in Finder,选择工程->Build Settings ,搜索框输入search,找到Header Serach Paths ,双击这行的右边,弹出一个大的输入框,把刚才Show in Finder的文件夹里面的Headers文件夹直接拖到大输入框里)
导入类库CoreLocation.framework,QuartzCore.framework,OpenGLES.framework,
SystemConfiguration.framework,CoreGraphics.framework,
Security.framework,libsqlite3.0.tbd,CoreTelephony.framework,libstdc++.6.0.9.tbd
….
解决 230 image not found 的问题(有时候工程无缘无故地在还没有进入的时候就崩了,很可能也是这里的问题,有一次我明明之前已经设置好了,没动过它,它也会自动地变成了NO,坑了好久)注意:Xcode 8 把这项改了名字:Always Embed Swift Standard Libraries
添加Bundle display name,并且在使用到百度SDK的文件中,把文件.m后缀改为.mm
允许https(在plist添加NSAppTransportSecurity,类型Dictionary ,在此目录下添加NSAllowsArbitraryLoads,类型boolean,值为YES;)
在buidsettings输入bite,选择Enable bite code,值为NO;
在plist添加NSLocationAlwaysUsageDescription
在工程的AppDelegate.h
在工程的AppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { _mapManager = [[BMKMapManager alloc]init]; BOOL ret = [_mapManager start:你在百度开放平台创建的AK generalDelegate:self]; if (!ret) { NSLog(@"manager start failed!"); } return YES; } (void)onGetNetworkState:(int)iError { if (0 == iError) { NSLog(@"联网成功"); } else{ NSLog(@"onGetNetworkState %d",iError); } } (void)onGetPermissionState:(int)iError { if (0 == iError) { NSLog(@"授权成功"); } else { NSLog(@"onGetPermissionState %d",iError); } }
13.在需要用到的控制器里
static NSString * entityName; static BTRACE * traceInstance = NULL; double latitudeOfEntity; double longitudeOfEntity; - (void)viewDidLoad { [super viewDidLoad]; _mapView=[[BMKMapView alloc] initWithFrame:self.view.frame]; _mapView.backgroundColor=[UIColor redColor]; [_mapView setZoomLevel:19]; pointAnnotation = nil; [self.view addSubview:_mapView]; [self doWork]; } -(void) doWork { //把设备的uuid作为entityName entityName = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; traceInstance = [[BTRACE alloc] initWithAk:AK mcode:MCODE serviceId:serviceID entityName: entityName operationMode: 2]; _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放 _mapView.mapType = BMKMapTypeStandard; //视图加载之后就请求实时位置 [self queryEntityList]; } //请求实时位置 - (void)queryEntityList { [[BTRACEAction shared] queryEntityList:self serviceId:serviceID entityNames:entityName columnKey:nil activeTime:0 returnType:0 pageSize:0 pageIndex:0]; } #pragma mark - Entity相关的回调方法 - (void)onQueryEntityList:(NSData *)data { NSString *entityListResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"实时位置查询结果: %@", entityListResult); //轨迹数据 NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:[entityListResult dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil]; //数据处理 } //添加当前位置的标注 -(void)addPointAnnotation { CLLocationCoordinate2D coord; coord.latitude = latitudeOfEntity; coord.longitude = longitudeOfEntity; if (nil == pointAnnotation) { pointAnnotation = [[BMKPointAnnotation alloc] init]; } pointAnnotation.coordinate = coord; CLLocationCoordinate2D pt=(CLLocationCoordinate2D){0,0}; pt=(CLLocationCoordinate2D){latitudeOfEntity,longitudeOfEntity}; pointAnnotation.title = @"最新位置"; dispatch_async(dispatch_get_main_queue(), ^{ [_mapView setCenterCoordinate:coord animated:true]; [_mapView addAnnotation:pointAnnotation]; }); } - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation { if (annotation == pointAnnotation) { NSString *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; } return nil; }
注意:1.bundle id ,工程里的mode,和百度开发者中心的安全码要保持一致,否则会出现只有白色网格的情况。
2. “230 image not found” Build Settings->Build Options->Always Embed Swift Standard Libraries->YES
3. “指定track不存在” 去到百度开发者官网的service_id那里,点击相应的ID的项目,创建一个entityName,或者选择某个entityName(如果有的话)去替换你工程里的 entityName
4. 更多未知问题请去官网论坛查看,有时候可能是因为官网未能及时更新,所以看看官网公告
iOS开发交流群:301058503
相关文章推荐
- C#开发Android百度地图手机应用程序(多地图展示)
- 百度地图给map添加右键菜单(判断是否为marker)
- 基于OL2实现百度地图ABCD marker的效果
- JS中引用百度地图并将百度地图的logo和信息去掉
- js调用百度地图及调用百度地图的搜索功能
- 基于Arcgis for javascript实现百度地图ABCD marker的效果
- 百度地图API提示230 错误app scode码校验失败的解决办法
- 微信企业号开发之微信考勤百度地图定位
- 百度地图自定义控件分享
- 基于Android实现百度地图定位过程详解
- Android百度地图应用之创建显示地图
- Android SDK 百度地图通过poi城市内检索简介接口的使用
- Android百度地图实现搜索和定位及自定义图标绘制并点击时弹出泡泡
- 如何调用百度地图API实现手机自动定位
- Android百度定位导航之基于百度地图移动获取位置和自动定位
- Android百度地图poi范围搜索
- Android 百度地图POI搜索功能实例代码
- 百度地图API使用方法详解
- javascript实现百度地图鼠标滑动事件显示、隐藏
- 如何根据百度地图计算出两地之间的驾驶距离(两种语言js和C#)