ios-地图 大头针的使用
2015-09-29 13:20
369 查看
#import "ViewController.h" //1.导入MKMapKit #import <MapKit/MapKit.h> @interface ViewController () - (IBAction)segmentHandle:(UISegmentedControl *)sender; @property (nonatomic, weak)MKMapView *mapView; @end @implementation ViewController - (IBAction)segmentHandle:(UISegmentedControl *)sender { /* MKMapTypeStandard 标准地图 MKMapTypeSatellite卫星地图 MKMapTypeHybrid 混合地图 */ MKMapType type; switch (sender.selectedSegmentIndex) { case 0: type = MKMapTypeStandard; //标准地图 break; case 1: type = MKMapTypeSatellite; //卫星地图 break; case 2: type = MKMapTypeHybrid; //混合地图 break; default: break; } self.mapView.mapType = type; } - (MKMapView *)mapView { if (!_mapView) { #if 0 MKMapView *mapView = [[MKMapView alloc]initWithFrame:self.view.bounds]; CLLocationCoordinate2D coordinate2D; //保存经纬度对象 coordinate2D.latitude = 39.9087607470; coordinate2D.longitude = 116.3975780490; //保存经纬度比例 MKCoordinateSpan span; //纬度 span.latitudeDelta = 1/100; span.longitudeDelta = 1/100; //范围:两部分 1.中心点经纬度 经纬度比例尺 MKCoordinateRegion region; region.center = coordinate2D; region.span = span; [mapView setRegion:region]; [self.view addSubview:mapView]; _mapView = mapView; #endif MKMapView *mapView = [[MKMapView alloc]initWithFrame:self.view.bounds]; //中心点经纬度 CLLocationCoordinate2D coordinate2D = {39.9087607478,116.3975780499}; //比例 MKCoordinateSpan span = {0.01,0.01}; //设置范围 [mapView setRegion:MKCoordinateRegionMake(coordinate2D, span)]; [self.view addSubview:mapView]; _mapView = mapView; } return _mapView; } /** * 添加标注 */ - (void)addAnnotation { CLLocationCoordinate2D coordinate2D = {39.9087607478,116.3975780499}; //大头针对象 MKPointAnnotation *pointAnnotation = [[MKPointAnnotation alloc]init]; pointAnnotation.coordinate = coordinate2D; //标题 pointAnnotation.title = @"北京市"; //子标题 pointAnnotation.subtitle = @"天安门"; //添加标注 [self.mapView addAnnotation:pointAnnotation]; #if 0 //1.添加一个标注 [self.mapView addAnnotation:<#(id<MKAnnotation>)#>]; //2.一次性添加多个标注 [self.mapView addAnnotations:<#(NSArray *)#>]; //3.移除指定标注 [self.mapView removeAnnotation:<#(id<MKAnnotation>)#>]; //4.移除多个标注 [self.mapView removeAnnotations:<#(NSArray *)#>]; //5.获取多个标注 self.mapView.annotations; //6.移除所有标注 [self.mapView removeAnnotations:self.mapView.annotations;]; #endif } - (void)viewDidLoad { [super viewDidLoad]; //地图显示类 MKMapView *mapView = [[MKMapView alloc]initWithFrame:self.view.bounds]; [self.view addSubview:mapView]; [self addAnnotation]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- ios获取设备信息总结
- iOS 9适配技巧
- iOS真机测试
- IOS 学习之路一 正其心
- iOS中关于控制器view加载顺序的个人总结
- iOS自动布局之通过代码添加约束
- IOS获取系统图片
- 解决iOS 9 symbolicatecrash卡死
- iOS 9学习系列:上手SFSafariViewController
- iOS开发实习期间get的技巧
- iOS 9适配技巧(更新版)
- iOS开发-图片加载优化
- [IOS]从零开始搭建基于Xcode7的IOS开发环境和免开发者帐号真机调试运行第一个IOS程序HelloWorld
- ios 除数为0时
- IOS欢迎界面Launch Screen动态加载广告
- iOS9中Bitcode的介绍及配置
- iOS Designated Initializers : Using NS_DESIGNATED_INITIALIZER
- iOS 使用AVFoundation 扫描二维码并限定扫描区域(带代码生成蒙版)
- note: declarations in dependent base ‘std::basic_ios<char>’ are not found by unqualified lookup
- iOS中如何使用PCH文件、修改其相对路径的方法