• 位置与地图(三)给地图加入覆盖层


    - (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;
    }
    */
  • 相关阅读:
    Microsoft Enterprise Library 5.0 系列(二) Cryptography Application Block (初级)
    Microsoft Enterprise Library 5.0 系列(五) Data Access Application Block
    Microsoft Enterprise Library 5.0 系列(八) Unity Dependency Injection and Interception
    Microsoft Enterprise Library 5.0 系列(九) Policy Injection Application Block
    Microsoft Enterprise Library 5.0 系列(三) Validation Application Block (高级)
    软件研发打油诗祝大家节日快乐
    从挖井的故事中想到开发管理中最容易忽视的几个简单道理
    ITIL管理思想的执行工具发布
    管理类软件设计“渔”之演化
    20070926日下午工作流与ITILQQ群 事件管理 讨论聊天记录
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/7159779.html
Copyright © 2020-2023  润新知