MapKit地图划线
只要用于获取用户位置都要取得用户授权
#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface ViewController ()<MKMapViewDelegate>
@property(nonatomic,strong)UITextField*destination;
@property(nonatomic,strong)MKMapView*mapView;
@property(nonatomic,strong)CLLocationManager *mgr;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.mgr=[[CLLocationManager alloc]init];
[self.mgr requestAlwaysAuthorization];
MKMapView *map=[[MKMapView alloc]init];
map.frame=self.view.bounds;
self.mapView=map;
[self.view addSubview:map];
self.mapView.delegate=self;
UITextField *field=[[UITextField alloc]init];
field.frame=CGRectMake(10, 20, 60, 30);
self.destination=field;
field.text=@"西安";
[self.view addSubview:field];
[self drawLine];
}
//划线
-(void)drawLine
{
[self.view endEditing:YES];
CLGeocoder *geo=[[CLGeocoder alloc]init];
[geo geocodeAddressString:self.destination.text completionHandler:^(NSArray *placemarks, NSError *error) {
if (placemarks.count==0||error) {
return ;
}
//获取目的地item 和当前的位置
CLPlacemark *pm=[placemarks firstObject];
MKPlacemark *mkp=[[MKPlacemark alloc]initWithPlacemark:pm];
MKMapItem *destinationItem=[[MKMapItem alloc]initWithPlacemark:mkp];
MKMapItem *userItem=[MKMapItem mapItemForCurrentLocation];
//1创建路线请求
MKDirectionsRequest*request=[[MKDirectionsRequest alloc]init];
//设置起点终点
request.source=userItem;
request.destination=destinationItem;
//创建路线管理器
MKDirections *direction=[[MKDirections alloc]initWithRequest:request];
//划线
[direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
for (MKRoute*route in response.routes) {
//拿到线
MKPolyline *line=route.polyline;
//添加到地图
[self.mapView addOverlay:line];
}
}];
}];
}
-(MKOverlayRenderer*)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
//创建渲染器
MKPolylineRenderer *render=[[MKPolylineRenderer alloc]initWithOverlay:overlay];
//设置线段的颜色
render.strokeColor=[UIColor redColor];
//设置线宽
render.lineWidth=5;
return render;
}
@end
MapKit地图划线的更多相关文章
- IOS6 IOS7 Mapkit draw Rout(地图划线)
IOS7 比较简单 CLLocationCoordinate2D _start2D; CLLocationCoordinate2D _end2D; NSArray *_routes; IOS6 ...
- iOS MapKit地图
地图框架:#import <MapKit/MapKit.h> 基本属性和方法: 属性: 地图类视图:MKMapView 地图类型:MKMapType mapType 地图旋转:rotate ...
- IOS原生地图与高德地图
原生地图 1.什么是LBS LBS: 基于位置的服务 Location Based Service 实际应用:大众点评,陌陌,微信,美团等需要用到地图或定位的App 2.定位方式 1.GPS定位 ...
- iOS之原生地图与高德地图
原生地图 1.什么是LBS LBS: 基于位置的服务 Location Based Service 实际应用:大众点评,陌陌,微信,美团等需要用到地图或定位的App 2.定位方式 1.GPS定位 2. ...
- iOS原生地图与高德地图的使用
原生地图 1.什么是LBS LBS: 基于位置的服务 Location Based Service 实际应用:大众点评,陌陌,微信,美团等需要用到地图或定位的App 2.定位方式 1.GPS定位 2. ...
- iOS完整学习步骤
一 C语言 1.1基本数据类型和基本运算 1.2 函数 数组 字符串 指针 1.3 预处理指令 1.4结构体 枚举 1.5 文件操作 内存管理 二 Objective - C 2.1 面向对象 2. ...
- CoreLocation框架的使用
CoreLocation框架使用 一.地图和定位的简介 1.应用场景 周边:找餐馆/找KTV/找电影院(团购APP) 导航:根据用户设定的起点和终点,进行路线规划,并指引用户如何到达(地图APP) 2 ...
- iOS框架介绍
iOS框架介绍 Cocoa Touch GameKit 实现对游戏中心的支持,让用户能够在线共享他们的游戏相关的信息 iOS设备之间蓝牙数据传输 从iOS7开始过期 局域网游 ...
- Frameworks(不定时更新)
iOS8.4 Frameworks 更新时间:2015年8月17日 Accelerate iOS4.0引入了Accelerate框架,该框架的接口可用于执行数学.大数字以及DSP运算.和开发者个人编写 ...
随机推荐
- django 添加comments app
django 添加comments app 参看 django comments 文档 安装和配置comments 1.安装comments,运行:pip install django-contrib ...
- iOS App Extensions 推荐文章
写的非常不错,读完后,基本的extension的套路就清楚了,也是我们的园友写的,感谢他: http://www.cnblogs.com/xdream86/p/3855932.html 下面这个教程是 ...
- Kafka集群环境搭建
Kafka是一个分布式.可分区.可复制的消息系统.Kafka将消息以topic为单位进行归纳:Kafka发布消息的程序称为producer,也叫生产者:Kafka预订topics并消费消息的程序称为c ...
- ABAP 销售范围
*&---------------------------------------------------------------------* *& Report ZSDR008 ...
- Python:IDLE清屏
清屏很简单,为IDLE增加一个清屏的扩展ClearWindow即可. 首先下载clearwindow.py(点击可直接下载,不能下载的可以右键保存,格式为py结尾), 将这个文件放到Python安装目 ...
- JS match() 方法 使用
javascript中的match函数是使用正则表达式对字符串进行查找,并将查找的结果作为数组返回,在实际开发中非常的有用,使用方法如下: stringObj.match(rgExp) 其中strin ...
- linq lanbda表达式的用法
1. 查询Student表中的所有记录的Sname.Ssex和Class列.select sname,ssex,class from studentLinq: from s in Student ...
- HTML5基本标签、样式
感觉在Sublime Text3中写起来比较方便~~ 将HTML5中要用到的基本标签全部放在了一起,没有好好的整理,为了自己记忆的方便,就先这样写下来了~~ <!DOCTYPE html> ...
- 20145213祁玮のJava课程总结
20145213のJava学习总结 每周学习笔记 1.第一周读书笔记 2.第二周读书笔记 3.第三周读书笔记 4.第四周读书笔记 5.第五周读书笔记 6.第六周读书笔记 7.第七周读书笔记 8.第八周 ...
- Jquery 提示还可以输入的字数,将多余的字数截取掉
js代码: $(function () { var counter = $("#divform textarea").val().length; //获取文本域的字符串长度 $( ...