2019独角兽企业重金招聘Python工程师标准>>>

我是最近接触的百度读图开发,百度地图的相关sdk api开发写的很简单,有很多都是写的不是很详细,但是如果我们想深究就会遇到很多问题,有许多我们想获得都东西往往都没法获得。直接步入正题吧,遇到问题如下:

一:我新申请的key,为啥没有用?地图没法加载,这个很有可能是你申请的key,有了,但是没有认证开发者,这就导致你的key没有用,地图没有加载出来,这个问题困扰了我很久才发现。

二:第一次使用百度地图的时候,必要的就是看Demo怎么使用这些方法。在使用官方Demo的时候地图真机测试就会出错,这个错误我大概记得,一个别忘申请新的key,二,别忘了选择证书,往往这个会导致错误

CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 9.2'

这个就是证书没有选择的错误

三:按照官方文档创建地图后以及写了相关方法,这里我就不多说了,值得注意的是如果我们如果想获取当前的经纬度的话就得引入定位服务,通过

[self.myLocationService startUserLocationService];

设置BMKLocationService

的代理人通过代理方法开启定位服务后就会执行updatelocation方法获取当前的经纬度,设置为地图中心点。值得注意的事,要在这停止定位服务,要不然的你的如何移动地图,地图的中心点会在隔几秒会回到原处。这是我个人的方法,不对的话,给我提出来。同事显示定位的图层

 self.myLocationService = [[BMKLocationService alloc]init];[self.myLocationService startUserLocationService];//开始定位服务
//    self.mapView.showsUserLocation = NO;
//    self.mapView.userTrackingMode = BMKUserTrackingModeFollow;
//    self.mapView.showsUserLocation = YES;self.myMapView.showsUserLocation = NO;self.myLocationService.delegate = self;self.myMapView.userTrackingMode = BMKUserTrackingModeFollow;//设置定位的状态self.myMapView.showsUserLocation = YES;//显示定位图层

四:自定义定位图层的图标,也许你们应该使用过百度的导航服务,仔细的人就会发现,地位图标是跟随样式,如果要因为这个图标旋转,就引入导航的SDK那就有点大材小用,导致APP的包过大,其实在我们可以重写这个

BMKLocationViewDisplayParam

这个类对象,根据将其中的imagename改成你的那个替换图片就行

 BMKLocationViewDisplayParam *param = [[BMKLocationViewDisplayParam alloc] init];param.isRotateAngleValid = YES;param.isAccuracyCircleShow = YES;param.locationViewImgName = @"icon_center_point1";param.locationViewOffsetX = 0;param.locationViewOffsetY = 0;[self.myMapView updateLocationViewWithParam:param];

icon_center_poin这个是boudle资源中的定位图层的那个图片名称,可以换成你想要的图片名称就行

五:自定义大投标,这个就需要你自己写一个类继承

BMKAnnotationView

这个类就行,然后就在其中创建你想要的一些信息,也可以创建paopaoView这个就是你点击这个大头针弹出的时候,你就可以自定义视图,想展示什么内容就展示什么内容。这个是我自定义大投标的的那个类。m文件中主要的方法

@interface LL_MapViewAnnotationView()
@property(nonatomic,strong)UIImageView *myHeadImageView;
@end
@implementation LL_MapViewAnnotationView
@synthesize headViewName;
-(id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];if (self) {[self setBounds:CGRectMake(0, 0, 50, 55)];UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 55)];[button setBackgroundImage:[UIImage imageNamed:@"btn_确定"] forState:UIControlStateNormal];[self addSubview:button];self.myHeadImageView = [[UIImageView alloc]initWithFrame:CGRectMake(2, 5, 45, 45)];self.myHeadImageView.clipsToBounds = YES;self.myHeadImageView.layer.cornerRadius = 22.5;[button addSubview:self.myHeadImageView];button.userInteractionEnabled = NO;BMKActionPaopaoView *paopaoView = [[BMKActionPaopaoView alloc]initWithCustomView:[self createPaopaoViewWithModel]];self.paopaoView = paopaoView;}return self;
}
-(UIView *)createPaopaoViewWithModel
{UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 250,143)];UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1, 143)];[view addSubview:lineView];UIView *allView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 250, 143)];[lineView addSubview:allView];
//    view.alpha = 0.4;allView.backgroundColor = [[Unity getColor:@"#000000"] colorWithAlphaComponent:0.4];//头像UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 8, 100, 100)];[imageView setImage:[UIImage imageNamed:@"img1"]];imageView.clipsToBounds = YES;imageView.layer.cornerRadius = 50;[view addSubview:imageView];//删除buttonUIButton *deleateBut =[[UIButton alloc]initWithFrame:CGRectMake(view.frame.size.width -5-20, 8, 20, 20)];[deleateBut setBackgroundImage:[UIImage imageNamed:@"ic_btn_Deleate"] forState:UIControlStateNormal];deleateBut.tag = 1001;[view addSubview:deleateBut];[deleateBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown];//距离LableUILabel *distence = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame)+20, 14, 101, 20)];[view addSubview:distence];NSMutableAttributedString *string = [[NSMutableAttributedString alloc]init];//添加图片的NSTextAttachment *attach = [[NSTextAttachment alloc]init];attach.image = [UIImage imageNamed:@"ic_find_Distence"];attach.bounds =CGRectMake(0, -5, 30, 20);NSAttributedString *attachString = [NSAttributedString attributedStringWithAttachment:attach];[string appendAttributedString:attachString];NSString *tempStr = [NSString stringWithFormat:@"  距离"];NSMutableAttributedString *textStr = [[NSMutableAttributedString alloc]initWithString:tempStr];[textStr addAttribute:NSForegroundColorAttributeName value:[Unity getColor:@"#FFFFFF"] range:NSMakeRange(0, tempStr.length)];[textStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, tempStr.length)];[string appendAttributedString:textStr];distence.attributedText = string;//距离数量LableUILabel *distenceNum = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(distence.frame), CGRectGetMaxY(distence.frame), view.frame.size.width-CGRectGetMinX(distence.frame)-40, 30)];NSString *distenceNumText = [NSString stringWithFormat:@"153  米"];NSMutableAttributedString *distenceString = [[NSMutableAttributedString alloc]initWithString:distenceNumText];[distenceString addAttribute:NSForegroundColorAttributeName value:[Unity getColor:@"#FFFFFF"] range:NSMakeRange(0, 3)];[distenceString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:19] range:NSMakeRange(0, 3)];[distenceString addAttribute:NSForegroundColorAttributeName value:[Unity getColor:@"#FDB100"] range:NSMakeRange(5, 1)];[distenceString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:NSMakeRange(5, 1)];distenceNum.attributedText = distenceString;distenceNum.textAlignment = NSTextAlignmentCenter;[view addSubview:distenceNum];UIView *downLoadView = [[UIView alloc]initWithFrame:CGRectMake(0, 90, 250, 53)];downLoadView.backgroundColor = [[Unity getColor:@"#4D4D4D"] colorWithAlphaComponent:0.5];[view addSubview:downLoadView];UIView *sexBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 35, 53)];[sexBackView setBackgroundColor:[Unity getColor:@"#FFB300"]];[downLoadView addSubview:sexBackView];UIImageView *sexImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 14, 25, 25)];[sexBackView addSubview:sexImageView];sexImageView.clipsToBounds = YES;sexImageView.layer.cornerRadius = 12.5;[sexBackView addSubview:sexImageView];[sexImageView setImage:[UIImage imageNamed:@"ic_男"]];//姓名lableUILabel *nameLable = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(sexBackView.frame)+12, 8, 120, 25)];nameLable.textColor = [Unity getColor:@"#FFFFFF"];nameLable.font = [UIFont systemFontOfSize:18];nameLable.text = @"张三";[downLoadView addSubview:nameLable];//个性签名UILabel *mySignText = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(nameLable.frame), CGRectGetMaxY(nameLable.frame), 120, 20)];mySignText.textColor = [Unity getColor:@"#FFFFFF"];mySignText.font = [UIFont systemFontOfSize:12];mySignText.text = @"个性签名";[downLoadView addSubview:mySignText];//查看buttonUIButton *lookButton = [[UIButton alloc]initWithFrame:CGRectMake(downLoadView.frame.size.width-10-80, 20, 80, 30)];[lookButton setImage:[UIImage imageNamed:@"ic_look_detail"] forState:UIControlStateNormal];[lookButton setTitle:@"查看" forState:UIControlStateNormal];[lookButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];lookButton.tag = 1002;[lookButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown];[downLoadView addSubview:lookButton];return view;
}

六:在创建大头针的时候也很简单和官方的说法一样,值得注意的就是添加其中的一些方法就行

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{NSString *AnnotationViewID = @"AnimatedAnnotation";LL_MapViewAnnotationView *annotationView = nil;if (annotationView == nil) {annotationView = [[LL_MapViewAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];[annotationView upHeadViewNameWithString:@"img1"];annotationView.myBlock = ^(NSInteger tag){switch (tag) {case 1001:{NSLog(@"删除按钮");}break;case 1002:{NSLog(@"查看按钮");}break;default:break;}};}return annotationView;}

这段代码是加大头针的方法,里面不要管别的,其他的不用想,想多了就很麻烦,我之前就是那样以为通过什么方法调用就行,其实这个跟tableView一样给个数据,设定高度,cell的数量,然后就是在代理方法中写返回的cell的样式就行

BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];CLLocationCoordinate2D coor;coor.latitude = 39.915;coor.longitude = 116.404;annotation.coordinate = coor;annotation.title = @"这里是北京";[self.myMapView addAnnotation:annotation];

其实还有别的问题,明天再说,今天有点累了,要睡觉了

转载于:https://my.oschina.net/u/2662567/blog/632450

iOS百度地图的相关开发(一)相关推荐

  1. ios 百度地图指定区域_ios百度地图的使用(普通定位、反地理编码)

    iOS定位 - 普通定位(没有地图) - 反地理编码(得到具体位置),下面通过代码给大家详解,代码如下: #import 使用到的头文件 要引入CoreLocation这个包 使用的代理名称 //1. ...

  2. 浅谈百度地图的简单开发再续前缘之公交,地铁路线检索查询(六)

    关于百度地图的简单开发前段时间,写过一个小系列的博客关于百度地图的基本地图,定位,全景,导航等功能做了简单的介绍.从今天开始又将准备一期有关百度地图的POI检索的等一列查询功能,如城市检索,周边检索, ...

  3. iOS百度地图SDK之实时绘制轨迹(后台仍执行)

    首先,对于百度地图SDK的配置和环境搭建就不做说明,需要的人可以博客中另一篇文章看 <iOS百度地图SDK基本使用> ,本文的重点在于实现实时绘制轨迹的功能,并且对细节进行处理和优化 1. ...

  4. 百度地图LBS应用开发代码

    最近因为工作需要,领导要我将51地图API开发的一个应用迁移到百度地图,或者说用百度地图API进行重写,实现同样的功能.我先是把现有的这个51地图的应用了解了一下,然后就试着用百度地图做一些demo, ...

  5. 浅谈百度地图的简单开发最后收官之实现导航功能(五)

    这篇是高仿百度地图的最后一篇了,今天主要来实现百度地图的导航的功能,并且该导航还自带语音播报功能,然后最后对整个百度地图开发过程遇到的问题进行一些列举,并给出一些解决的办法,可能总结的不是很齐全,希望 ...

  6. ios 苹果和百度地图的相关使用

    iOS中使用较多的3款地图,google地图.百度地图.苹果自带地图(高德).其中苹果自带地图在中国使用的是高德的数据.苹果在iOS 6之后放弃了使用谷歌地图,而改用自家的地图.在国内使用的较多的就是 ...

  7. iOS 百度地图开发集成使用 (转)

    m 项目需要集成百度地图,那么关于如何集成百度地图的事,就自己去百度开放平台查看文档吧,这是非常简单的事,在这里就不多说了. 那么下面我就说说我在这个demo里所做的事. 首先,项目需要具备定位及计算 ...

  8. iOS 百度地图开发集成使用

    项目需要集成百度地图,那么关于如何集成百度地图的事,就自己去百度开放平台查看文档吧,这是非常简单的事,在这里就不多说了. 那么下面我就说说我在这个demo里所做的事. 首先,项目需要具备定位及计算两地 ...

  9. ios 百度地图指定区域_iOS开发(第三方使用)——百度地图的简单使用(定位与当前位置的显示)...

    使用cocoapods导入 pod 'BaiduMapKit' 在plist添加NSLocationAlwaysUsageDescription 去百度地图开发者中心注册帐号,并创建项目,拿到AK的值 ...

最新文章

  1. Fragment全解析系列
  2. Python Setuptools 升级(Upgrade)
  3. list所有元素相加 python_Python基础入门笔记:列表、元组(阿里云天池)
  4. python聊天程序程序代码_python聊天程序实例代码分享
  5. P3387-【模板】缩点【tarjan,强联通分量,DAGdp】
  6. popoverController(iPad)
  7. Python rsa 加密
  8. Chapter 04-Using Conversion Functions and Conditional Expressions-Conditional Expressions
  9. 【进阶修炼】——改善C#程序质量(5)
  10. 微信插件制作之抢红包入门篇
  11. 基于android的手机选课系统的实现
  12. 《.NET程序员面试秘籍》读书笔记
  13. 【数据结构与算法分析】证logXX 对所有的X0成立
  14. Excel序号删除某行之后不连贯?这样做可以智能更新表格序号!
  15. excel无法打开文件,因为文件格式或文件扩展名无效
  16. 批归一化《Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift》
  17. 怎么打印加密的PDF文件?
  18. 如何配置Tomcat服务器
  19. 纯卡西欧计算器5800P坐标正反算
  20. H3CSE20200603班-IPv6路由协议

热门文章

  1. Devpress.XtraGrid.GridControl.GridView属性
  2. Spring MVC Formatter(数据格式化)详解
  3. 03-25 内存统计
  4. 软件测试模型-V模型
  5. 线性插值改变图像尺寸_图像分割--gt;上采样的那些事
  6. 温州服务器付费方式_新购买的服务器是选择包年包月还是按流量计费呢?
  7. mysql order by 固定_MySQL 强制操作以及order by 使用
  8. 文件操作(文件指针+顺序/随机读写)
  9. 随便创建Servlet文件都出现,请求资源不可用的情况
  10. 计算机无法共享磁盘分区,win7系统下怎么创建虚拟磁盘分区以达到网络共享的目的...