自定义Google Map样式的蓝点表示当前位置和精确度
来源:互联网 发布:软件水平考试报名 编辑:程序博客网 时间:2024/04/29 05:52
用了MapKit的同学用不着这个,只是为了自定义地图引擎用的。
其实主要的想法就是创建一个CALayer的子类,包含两个部分,一个始终居中的蓝色图标,和一个圆形的layer背景表示GPS的精确度。每次GPS更新后,通过修改layer的大小,实现像Googlemap那个蓝点一样的效果。layer的大小通过计算地图比例尺得到,然后再根据CLLocation中的horizontalAccuracy计算出来。比如已知地图两个上端点的坐标,计算这两个点的实际距离,然后计算出这个距离与显示像素的比例,那么layer的大小就是:
其实主要的想法就是创建一个CALayer的子类,包含两个部分,一个始终居中的蓝色图标,和一个圆形的layer背景表示GPS的精确度。每次GPS更新后,通过修改layer的大小,实现像Googlemap那个蓝点一样的效果。layer的大小通过计算地图比例尺得到,然后再根据CLLocation中的horizontalAccuracy计算出来。比如已知地图两个上端点的坐标,计算这两个点的实际距离,然后计算出这个距离与显示像素的比例,那么layer的大小就是:
diameter = accuracy/(distance/nbPixs)
/** * @file BlueCircleLayer.h * @author * @date * @version * @description * @copyright * @brief */ @interface BlueCircleLayer : CALayer { } /*! * change the size, keey as a circle */- (void)resize:(CGFloat)diameter; @end
/** * @file BlueCircleLayer.m * @author * @date * @version * @description * @copyright * @brief */ #import "BlueCircleLayer.h" @implementation BlueCircleLayer /*! * @override */- (id)init{ self = [super init]; if (self) { [self setNeedsDisplayOnBoundsChange:TRUE]; [self setBorderWidth:1]; [self setBorderColor:[[UIColor colorWithRed:64/255.0f green:87/255.0f blue:188/255.0f alpha:1] CGColor]]; [self setBackgroundColor:[[UIColor colorWithRed:102/255.0f green:153/255.0f blue:255/255.0f alpha:0.3f] CGColor]]; } return self;} /*! * @override */- (void)drawInContext:(CGContextRef)ctx{ UIImage * image = [UIImage imageNamed:@"bluePoint.png"]; //keep the blue point is in the center of the layer CGContextDrawImage(ctx, CGRectMake(self.frame.size.width/2.0f - 10, self.frame.size.height/2.0f - 11, 21, 23), image.CGImage);} /*! * change the size, keey as a circle * @param diameter diameter of the circle */- (void)resize:(CGFloat)diameter{ if (diameter >= 25) { //if smaller than the img [self setBorderWidth:1]; [self setBorderColor:[[UIColor colorWithRed:64/255.0f green:87/255.0f blue:188/255.0f alpha:1] CGColor]]; [self setBackgroundColor:[[UIColor colorWithRed:102/255.0f green:153/255.0f blue:255/255.0f alpha:0.3f] CGColor]]; [self setFrame:CGRectMake(0, 0, diameter, diameter)]; [self setCornerRadius:diameter/2.0f]; } else { [self setBackgroundColor:[[UIColor clearColor] CGColor]]; [self setBorderColor:[[UIColor clearColor] CGColor]]; [self setFrame:CGRectMake(0, 0, 25, 25)]; } } @end
- 自定义Google Map样式的蓝点表示当前位置和精确度
- Android Google Map 地图中自定义当前位置
- 亚像素级精确度的角点
- Baidu 地图和Google地图对同一点的坐标表示不完全一致,如何解决?
- html5中利用google map,处理当前位置相关应用
- google map 自定义控件
- Google Map 自定义infowindow
- google map 自定义infowindow
- Google map 点线面 - 点
- 蓝桥 2的次幂表示
- 在Google map中添加kml文件的注意点
- 利用Google Map获得某点的经纬度
- 蓝点通用管理系统V13.0 Internet网络版破解应用无穷的自定义管理软件平台
- google map 自定义右键菜单
- google Map A自定义控件
- Google Map API Version3 教程(五):地图控件的自定义
- hdoj1063&&poj1001 Exponentiation(大数据的处理,浮点数的幂高精确度表示)
- mappoint和google map
- emacs使用doxymacs
- Tomcat成功安装并且正常启动
- 部署Data Guard相关参数详解
- flex学习一
- 迅雷开放的API接口函数定义
- 自定义Google Map样式的蓝点表示当前位置和精确度
- 小错误集锦(更新自己不熟悉的小错误)
- 请各位高手帮忙解释两个实物电路
- python time模块详解
- RTEMS的板级调试
- Java中Map的三种遍历方法
- bat 创建一个文件夹,复制bat脚本,判断文件夹,并删除文件夹
- 抽象类和接口的区别
- 反射重载方法(发现不明确的匹配)