Oc 地图覆盖层
来源:互联网 发布:算法c语言实现高清pdf 编辑:程序博客网 时间:2024/05/18 19:39
实现代码
#import <MapKit/MapKit.h>#import "FKViewController.h"@interface FKViewController () <MKMapViewDelegate>@property (nonatomic, strong) MKMapView* mapView;@end@implementation FKViewController- (void)viewDidLoad{ [super viewDidLoad]; self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; self.mapView.zoomEnabled = YES; // 设置地图可滚动 self.mapView.scrollEnabled = YES; // 设置地图不可旋转 self.mapView.rotateEnabled = NO; // 设置地图显示用户位置 self.mapView.showsUserLocation = YES; [self.view addSubview:self.mapView]; [self locateToLatitude:23.126272 longitude:113.395568]; // 创建一个手势处理器,用于检测、处理长按手势 UILongPressGestureRecognizer* gesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)]; [self.mapView addGestureRecognizer:gesture]; self.mapView.delegate = self;}- (void)locateToLatitude:(CGFloat)latitude longitude:(CGFloat)longitude{ // 设置地图中心的经、纬度 CLLocationCoordinate2D center = {latitude , longitude}; // 设置地图显示的范围, MKCoordinateSpan span; // 地图显示范围越小,细节越清楚 span.latitudeDelta = 0.01; span.longitudeDelta = 0.01; // 创建MKCoordinateRegion对象,该对象代表了地图的显示中心和显示范围。 MKCoordinateRegion region = {center,span}; // 设置当前地图的显示中心和显示范围 [self.mapView setRegion:region animated:YES];}- (void) longPress:(UILongPressGestureRecognizer*)gesture{ // 获取长按点的坐标 CGPoint pos = [gesture locationInView:self.mapView]; // 将长按点的坐标转换为经度、维度值 CLLocationCoordinate2D coord = [self.mapView convertPoint:pos toCoordinateFromView:self.mapView]; // 创建MKCircle对象,该对象代表覆盖层 MKCircle* circle = [MKCircle circleWithCenterCoordinate:coord radius:100]; // 添加MKOverlay [self.mapView addOverlay:circle level:MKOverlayLevelAboveLabels];}// MKMapViewDelegate协议中的方法,该方法返回的MKOverlayRenderer负责绘制覆盖层控件- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{ MKCircle * circle = (MKCircle*)overlay; // 创建一个MKCircleRenderer对象 MKCircleRenderer* render = [[MKCircleRenderer alloc] initWithCircle:circle]; // 设置MKCircleRenderer的透明度 render.alpha = 0.5; // 设置MKCircleRenderer的填充颜色和边框颜色 render.fillColor = [UIColor blueColor]; render.strokeColor = [UIColor redColor]; return render;}@end
阅读全文
0 0
- Oc 地图覆盖层
- 覆盖层
- 位置与地图(三)给地图添加覆盖层
- 百度地图覆盖层OverLayer用自定义的View来替换
- oc地图
- js 覆盖层
- OC地图简洁版
- oc地图带字典
- Oc LocateMap(地图定位)
- Oc CLGeocoder(地图解析)
- Oc 地图锚点
- Javascript 弹出覆盖层 Demo
- ios之oc省市区小地图
- 高德地图关键字搜索oc版
- jquery blockui 调整覆盖层颜色
- jsp 创建 覆盖层DIV 怎么创建 【源代码】
- UITableViewCell delete button 上有其它覆盖层
- jq给页面添加覆盖层遮罩
- 类的创建并实例化
- SQL 添加中文记录;SQL 删除记录;删除所有内容(记录);delete和truncate的区别
- TCP的三次握手
- JAVA面向对象练习
- 实验二线性表综合实验4
- Oc 地图覆盖层
- virtualenv在ubuntu上的使用
- Oc iPad开发~dome
- HMM隐马尔科夫模型例题讲解 加深印象
- 图形用户界面
- (机器学习基石)Machine Learning Foundations:Lecture 2
- Oc iPad与iPhone兼容~demo
- java菱形
- sql查询过程