IOS网络笔记--地图内容1
2015-10-27 18:13
441 查看
申明:此为本人学习笔记,若有纰漏错误之处的可留言共同探讨
/*
地图功能
思路
一个MKMapView(地图页面) 一个UISegmentedControl(分段控件) 一个MKCoordinateRegion(区域)
地图页面和分段控件在self.view上,区域在地图页面上,区域有中心点和精确度
操作步骤
1.加入库MapKit、CoreGraphics 导入头文件<MapKit/MapKit.h>
2.创建一个全局变量MKMapView
3.初始化mapView,加入视图
4.创建分段控件UISegmentedControl(有时称为按钮栏),设置属性和方法
5.设置地图中心点、可视范围、加入区域内
6.把设置好的区域加入到mapView内
*/
具体代码部分:
#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface ViewController ()
{
MKMapView *mapView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 初始化mapView
mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height-60)];
[self.view addSubview:mapView];
// 分段控件
UISegmentedControl *type = [[UISegmentedControl alloc]initWithItems:@[@"普通地图",@"卫星地图",@"混合地图"]];
type.frame =CGRectMake(0, 20, self.view.frame.size.width, 40);
[self.view addSubview:type];
[type addTarget:self action:@selector(ChangeType:) forControlEvents:UIControlEventValueChanged];
/* 设置地图的初始位置 参数
1 纬度
2 经度
*/
// 中心点的坐标
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(22.545734, 113.987004);
// 设置可视范围 数字越小显示的范围越小(内容越详细)
MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.01);
// 数据显示在地图上
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
[mapView setRegion:region animated:YES];
}
#pragma mark - 分段控件点击事件
-(void)ChangeType:(UISegmentedControl*)type
{
switch (type.selectedSegmentIndex) {
case 0:
mapView.mapType = MKMapTypeStandard; // 普通
break;
case 1:
mapView.mapType = MKMapTypeSatellite; // 卫星
break;
case 2:
mapView.mapType = MKMapTypeHybrid; // 混合
break;
default:
break;
}
}
附上完整Demo:http://download.csdn.net/detail/csdn_hhg/9217933
/*
地图功能
思路
一个MKMapView(地图页面) 一个UISegmentedControl(分段控件) 一个MKCoordinateRegion(区域)
地图页面和分段控件在self.view上,区域在地图页面上,区域有中心点和精确度
操作步骤
1.加入库MapKit、CoreGraphics 导入头文件<MapKit/MapKit.h>
2.创建一个全局变量MKMapView
3.初始化mapView,加入视图
4.创建分段控件UISegmentedControl(有时称为按钮栏),设置属性和方法
5.设置地图中心点、可视范围、加入区域内
6.把设置好的区域加入到mapView内
*/
具体代码部分:
#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface ViewController ()
{
MKMapView *mapView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 初始化mapView
mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height-60)];
[self.view addSubview:mapView];
// 分段控件
UISegmentedControl *type = [[UISegmentedControl alloc]initWithItems:@[@"普通地图",@"卫星地图",@"混合地图"]];
type.frame =CGRectMake(0, 20, self.view.frame.size.width, 40);
[self.view addSubview:type];
[type addTarget:self action:@selector(ChangeType:) forControlEvents:UIControlEventValueChanged];
/* 设置地图的初始位置 参数
1 纬度
2 经度
*/
// 中心点的坐标
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(22.545734, 113.987004);
// 设置可视范围 数字越小显示的范围越小(内容越详细)
MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.01);
// 数据显示在地图上
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
[mapView setRegion:region animated:YES];
}
#pragma mark - 分段控件点击事件
-(void)ChangeType:(UISegmentedControl*)type
{
switch (type.selectedSegmentIndex) {
case 0:
mapView.mapType = MKMapTypeStandard; // 普通
break;
case 1:
mapView.mapType = MKMapTypeSatellite; // 卫星
break;
case 2:
mapView.mapType = MKMapTypeHybrid; // 混合
break;
default:
break;
}
}
附上完整Demo:http://download.csdn.net/detail/csdn_hhg/9217933
相关文章推荐
- Java之网络爬虫WebCollector+selenium+phantomjs(三)
- http post/get 2种使用方式
- http post/get 2种使用方式
- 网络营销广告的类型(CPC、CPM、CPA、CPS, CTR)
- 卷积神经网络中卷积概念的理解
- iOS网络请求---1
- linux socket 设置从哪个网络设备发送数据 SO_BINDTODEVICE
- android 判断当前网络是否可用
- 通过URLHttpConnection方式连接网络步骤,获取位图为例
- Tomcat部署成Https模式的方法
- 【UFLDL】多层神经网络
- Pawn Storm网络间谍行动再度现身
- 【iOS】使用 Reachability 第三方库 检测网络
- 使用TCP传输从客户端上传文件到服务器端
- tcp三次握手、socket编程
- TCP/IP
- Android判断网络是否连接
- 计算机基础--网络基础专项练习笔记
- 深入理解HTTP Session
- HTTP协议的作用原理