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运算.和开发者个人编写 ...
随机推荐
- ios中的addChildViewController 和 android中的fragment
刚才突然感觉这2个东西的功能特别像,记录一下,待研究!
- ACM/ICPC 之 两道dijkstra练习题(ZOJ1053(POJ1122)-ZOJ1053)
两道较为典型的单源最短路径问题,采用dijkstra解法 本来是四道练习题,后来发现后面两道用dijkstra来解的话总觉得有点冗余了,因此暂且分成三篇博客(本篇以及后两篇). ZOJ1053(POJ ...
- Linux实时流量监控工具 - iftop
*本文转自ggjucheng的博客 介绍 iftop是一款实时流量监控工具,监控TCP/IP连接等,缺点就是无报表功能.必须以root身份才能运行. 实例 默认是监控第一块网卡的流量 iftop 监控 ...
- C#字符串的四舍五入
Round(Decimal) Round(Double) Round(Decimal, Int32) Round(Decimal, MidpointRounding) Round(Double, In ...
- 【leetcode】Max Points on a Line(hard)☆
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- 【编程题目】一串首尾相连的珠子(m 个),有 N 种颜色(N<=10),取出其中一段,要求包含所有 N 中颜色,并使长度最短。
40.百度研发笔试题 2)一串首尾相连的珠子(m 个),有 N 种颜色(N<=10),设计一个算法,取出其中一段,要求包含所有 N 中颜色,并使长度最短.并分析时间复杂度与空间复杂度. 思路: ...
- 混合高斯模型:opencv中MOG2的代码结构梳理
/* 头文件:OurGaussmix2.h */ #include "opencv2/core/core.hpp" #include <list> #include&q ...
- dropdownlist 动态添加
this.DropDownList1.Items.Insert(0,new ListItem("","")); this.Drop ...
- ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(七) 之 历史记录查询(时间,关键字,图片,文件),关键字高亮显示。
前言 上一篇讲解了如何自定义右键菜单,都是前端的内容,本篇内容就一个:查询.聊天历史纪录查询,在之前介绍查找好友的那篇博客里已经提到过 Elasticsearch,今天它又要上场了.对于Elastic ...
- CLR via C#(12)-委托Delegate
本来按照进度应该学习事件了,可总觉得应该委托在前,事件在后,才好理解. 委托是一个类,它提供了回调函数机制,而且是类型安全的.使用委托可以将方法当作另一个方法的参数来进行传递,这种将方法动态地赋给参数 ...