位置与地图(三)给地图添加覆盖层
来源:互联网 发布:java标识符的命名测试 编辑:程序博客网 时间:2024/05/24 20:07
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; self.mapView.mapType = MKMapTypeStandard; self.mapView.scrollEnabled = YES; // 设置地图不可旋转 self.mapView.rotateEnabled = NO; self.mapView.zoomEnabled = YES; self.mapView.showsUserLocation = YES; // 设置地图中心的经纬度 CLLocationCoordinate2D center = {39.910650,116.47030}; // 设置地图显示的范围,数值越小细节越清楚 MKCoordinateSpan span = {0.01,0.01}; // 二者合一设置显示区域 MKCoordinateRegion region = {center,span}; [self.mapView setRegion:region animated:YES]; [self.view addSubview:self.mapView]; UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; [self.mapView addGestureRecognizer:longGesture]; // 设置代理 self.mapView.delegate = self; }- (void)longPress:(UILongPressGestureRecognizer *)longGesture{ // 获取长按点得坐标 CGPoint postion = [longGesture locationInView:self.mapView]; // 将长按点坐标转换为经纬度 CLLocationCoordinate2D coord2D = [self.mapView convertPoint:postion toCoordinateFromView:self.mapView]; // 创建一个圆形覆盖层对象 MKCircle *circle = [MKCircle circleWithCenterCoordinate:coord2D radius:100]; // 将单个的覆盖层添加到指定的层级 [self.mapView addOverlay:circle level:MKOverlayLevelAboveLabels]; }// 该方法返回的MKOverlayRenderer负责绘制覆盖层控件- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{ MKCircle *circle = (MKCircle *)overlay; // iOS7之后,推荐使用MKXxxRenderer来负责渲染覆盖层控件 MKCircleRenderer *circleRend = [[MKCircleRenderer alloc] initWithCircle:circle]; circleRend.alpha = 0.3; // 填充颜色 circleRend.fillColor = [UIColor blueColor]; // 边框颜色 circleRend.strokeColor = [UIColor redColor]; return circleRend;}/*********iOS7新增的MKTileOverlay覆盖层*******************************************- (void)longPress:(UILongPressGestureRecognizer *)longGesture{ // 指定本地图片覆盖 NSURL *url = [[NSBundle mainBundle] URLForResource:@"hmt" withExtension:@"png"]; MKTileOverlay *tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:[url description]]; [self.mapView addOverlay:tileOverlay]; }// 该方法返回的MKOverlayRenderer负责绘制覆盖层控件- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{ MKTileOverlayRenderer *tileRender = [[MKTileOverlayRenderer alloc] initWithOverlay:(MKTileOverlay *)overlay]; tileRender.alpha = 0.2; return circleRend;}*/
4 1
- 位置与地图(三)给地图添加覆盖层
- Oc 地图覆盖层
- 给地图添加标注
- 位置与地图:地图的使用
- 地图添加与获取
- 位置与地图(二)地图的使用以及标注地图
- iOS 位置与地图相关
- 【android基础】位置与地图
- jq给页面添加覆盖层遮罩
- [android学习]给地图添加要素
- 百度地图覆盖层OverLayer用自定义的View来替换
- 添加地图
- 标记位置与放大、缩小地图
- 18.5 位置与地图:创建标注视图
- ios 地图与定位(用户位置)
- 三、百度地图二次开发添加控件
- 位置与地图:定位获取设备的位置
- 位置与地图:几种位置反编码方式
- java系统之间的调用
- 分页 很实用
- 图片的一些效果处理方法
- 冒泡排序和选择法排序
- 个人对码表的理解(ASCII,GBK,Unicode,UTF-8等)。
- 位置与地图(三)给地图添加覆盖层
- kkk
- 流媒体服务器
- Oracle数据库技术
- 嵌入式 linux下线程池小结c语言
- GifView——Android显示GIF动画
- WinCE显示ResidentFlash盘符(文件夹)
- ADO+MFC数据库编程常用语句
- html中Form学习实例