博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
位置与地图(三)给地图加入覆盖层
阅读量:6914 次
发布时间:2019-06-27

本文共 2551 字,大约阅读时间需要 8 分钟。

- (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
)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
)overlay{ MKTileOverlayRenderer *tileRender = [[MKTileOverlayRenderer alloc] initWithOverlay:(MKTileOverlay *)overlay]; tileRender.alpha = 0.2; return circleRend;}*/
你可能感兴趣的文章
Swift3.0语言教程比较、判断字符串
查看>>
只用来保存JQuery lightbox图片用的
查看>>
pdftk的使用介绍
查看>>
hibernate _关联级别策略介绍
查看>>
Word如何快速绘制你需要的作文稿纸
查看>>
币圈的黄埔军校,徐明星的傲慢与偏见
查看>>
全球直播的罗胖跨年演讲背后技术支撑故事——罗辑思维首席架构师方圆访谈...
查看>>
万能的淘宝再现实力“魔术手”,沙县小吃摇身变成“萌系治愈所”
查看>>
勒索病毒致世界天翻地覆 360安全卫士离线救灾版扭转乾坤
查看>>
排插新国标将实施,传统排插企业满脸“尴尬”?
查看>>
36岁辞职创业,5名员工,如今年销售额50亿!
查看>>
势不可挡!荣耀双11再夺销量和销售额的双料冠军
查看>>
华为Mate 10 Pro:4800秒从0%至100%的神奇电池
查看>>
PCIe NVMe SSD准备”蚕食”企业级存储系统了
查看>>
“引江济淮”工程全线开工 将建全球单跨最大渡槽
查看>>
青瓦台:特朗普未曾提及韩方协防分担费具体数额
查看>>
福岛第一核电站将撤除屋顶钢筋 为取出燃料做准备
查看>>
贵阳铁路警方早谋划 多举措备战春运保安全
查看>>
“全国百名杰出新型职业农民”刘良军:从医官到村官
查看>>
深商全球大会:百果园获评“深圳老字号”
查看>>