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运算.和开发者个人编写 ...
 
随机推荐
- 一个不错的定位API网站
			
2015年5月2日 15:36:31 星期六 http://www.haoservice.com/
 - Effective C++ -----条款34:区分接口继承和实现继承
			
接口继承和实现继承不同.在public继承之下,derived classes总是继承base class的接口. pure virtual函数只具体指定接口继承. 简朴的(非纯)impure vir ...
 - codeforces  582A. GCD Table  解题报告
			
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
 - WebService到底是什?
			
一.序言 大家或多或少都听过WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成分.但是不得不承认的是Web ...
 - jquery 中的一写常用方法
			
$('form').submit(); // 表单提交 window.parent.location.reload(); // 子窗口刷新父页面 window.location.reload(); / ...
 - 【leetcode】Balanced Binary Tree(middle)
			
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
 - ShareSdk使用心得
			
1. 微信和朋友圈:分享的时候设置了链接和图片,但就是不显示: 需要指明ShareType为WEB_PAGE 2. 需要完整添加 ShareSdk 的所需要的权限,不然分享闪退,并且不报异常:网络请求 ...
 - Xcode常用代码块
			
Xcode的代码片段(Code Snippets)创建自定义的代码片段,当你重用这些代码片段时,会给你带来很大的方便. 常用的: 1.strong:@property (nonatomic,stron ...
 - 启动ip转法功能
			
这种方法无需重启: [root@ha02 ~]# cat /proc/sys/net/ipv4/ip_forward [root@ha02 ~]# sysctl -w net.ipv4.ip_forw ...
 - MVC公开课 – 1.基础 (2013-3-15广州传智MVC公开课)
			
1.MVC设计模式 Model 是指 要处理的业务代码和数据操作代码 View 视图 主要是指的 跟用户打交道 并能够展示数据 Controller 看成是 Model和View的桥梁 优点: 1 ...