ios 百度鹰眼集成

百度鹰眼集成遇到的坑
下面说一下集成步骤很全
1,使用cocoapods导入百度地图的基础的SDK: pod ‘BaiduMapKit’

2,登录百度地图开放平台,找到iOS的鹰眼轨迹的SDK,下载,然后把BaiduTraceSDK.framework导入工程(选择工程->General ,把SDK拖到Embedded Baniaries)


如图.png

3,设置头文件路径(选择刚刚导入的SDK,Show in Finder,选择工程->Build Settings ,搜索框输入search,找到Header Serach Paths ,双击这行的右边,弹出一个大的输入框,把刚才Show in Finder的文件夹里面的Headers文件夹直接拖到大输入框里)


如图.png

4,导入类库CoreLocation.framework,QuartzCore.framework,OpenGLES.framework,
SystemConfiguration.framework,CoreGraphics.framework,
Security.framework,libsqlite3.0.tbd,CoreTelephony.framework,libstdc++.6.0.9.tbd

5…. 所谓开启后台位置定位


如图.png

6,解决 230 image not found 的问题(有时候工程无缘无故地在还没有进入的时候就崩了,很可能也是这里的问题,有一次我明明之前已经设置好了,没动过它,它也会自动地变成了NO,坑了好久)注意:Xcode 8 把这项改了名字:Always Embed Swift Standard Libraries


如图.png

7,添加Bundle display name,并且在使用到百度SDK的文件中,把文件.m后缀改为.mm

8,允许https(在plist添加NSAppTransportSecurity,类型Dictionary ,在此目录下添加NSAllowsArbitraryLoads,类型boolean,值为YES;)

9,在buidsettings输入bite,选择Enable bite code,值为NO;

10,在plist添加NSLocationAlwaysUsageDescription

11,在工程的AppDelegate.h


如图.png

12,在工程的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,在需要用到的控制器里


如图.png
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];
    NSNumber *status = [dic objectForKey:@"status"];
    if (0 == [status longValue]) {
        NSArray *entities = [dic objectForKey:@"entities"];
        NSDictionary *entity = [entities objectAtIndex:0];
        NSDictionary *realtimePoint = [entity objectForKey:@"realtime_point"];
        NSArray *location = [realtimePoint objectForKey:@"location"];
        longitudeOfEntity = [[location objectAtIndex:0] doubleValue];
        latitudeOfEntity = [[location objectAtIndex:1] doubleValue];
        dispatch_async(dispatch_get_main_queue(), ^{
            [_mapView removeOverlays:_mapView.overlays];
            [_mapView removeAnnotations:_mapView.annotations];
        });
        [self addPointAnnotation];
    }
}


//添加当前位置的标注
-(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,和百度开发者中心的安全码要保持一致,否则会出现只有白色网格的情况。

  1. “230 image not found” Build Options->Enabled Content Contains Swift Code(Xcode 8 的是Always Embed Swift Standard Libraries)->YES
  2. “指定track不存在” 去到百度开发者官网的service_id那里,点击相应的ID的项目,创建一个entityName,或者选择某个entityName(如果有的话)去替换你工程里的 entityName

如果跑步起来看这里看这里


1.png
1.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,425评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,058评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,186评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,848评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,249评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,554评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,830评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,536评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,239评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,505评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,004评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,346评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,999评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,060评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,821评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,574评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,480评论 2 267

推荐阅读更多精彩内容