只要用于获取用户位置都要取得用户授权

#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地图划线的更多相关文章

  1. IOS6 IOS7 Mapkit draw Rout(地图划线)

    IOS7  比较简单 CLLocationCoordinate2D  _start2D; CLLocationCoordinate2D  _end2D; NSArray *_routes; IOS6 ...

  2. iOS MapKit地图

    地图框架:#import <MapKit/MapKit.h> 基本属性和方法: 属性: 地图类视图:MKMapView 地图类型:MKMapType mapType 地图旋转:rotate ...

  3. IOS原生地图与高德地图

    原生地图 1.什么是LBS LBS: 基于位置的服务   Location Based Service 实际应用:大众点评,陌陌,微信,美团等需要用到地图或定位的App 2.定位方式 1.GPS定位  ...

  4. iOS之原生地图与高德地图

    原生地图 1.什么是LBS LBS: 基于位置的服务 Location Based Service 实际应用:大众点评,陌陌,微信,美团等需要用到地图或定位的App 2.定位方式 1.GPS定位 2. ...

  5. iOS原生地图与高德地图的使用

    原生地图 1.什么是LBS LBS: 基于位置的服务 Location Based Service 实际应用:大众点评,陌陌,微信,美团等需要用到地图或定位的App 2.定位方式 1.GPS定位 2. ...

  6. iOS完整学习步骤

    一  C语言 1.1基本数据类型和基本运算 1.2 函数 数组 字符串 指针 1.3 预处理指令 1.4结构体 枚举 1.5 文件操作 内存管理 二 Objective - C 2.1 面向对象 2. ...

  7. CoreLocation框架的使用

    CoreLocation框架使用 一.地图和定位的简介 1.应用场景 周边:找餐馆/找KTV/找电影院(团购APP) 导航:根据用户设定的起点和终点,进行路线规划,并指引用户如何到达(地图APP) 2 ...

  8. iOS框架介绍

    iOS框架介绍      Cocoa Touch   GameKit  实现对游戏中心的支持,让用户能够在线共享他们的游戏相关的信息  iOS设备之间蓝牙数据传输   从iOS7开始过期   局域网游 ...

  9. Frameworks(不定时更新)

    iOS8.4 Frameworks 更新时间:2015年8月17日 Accelerate iOS4.0引入了Accelerate框架,该框架的接口可用于执行数学.大数字以及DSP运算.和开发者个人编写 ...

随机推荐

  1. iso网络各层协议

    (1)网卡的作用就是把数据进行串并转换(串连数据是比特流形式的,存在与本计算机内部,而计算机与计算机之间是通过帧形式的数据来进行数据传输的),MAC子层规定了如何在物理线路上传输的frame,LLC的 ...

  2. iOS cannot find folder xcdatamodeld Xcode 7

    今天升级xcode7时发现了个这个编译bug,说是找不到xcdatamodeld. 解决方法如下: I had the same problem. Here are the steps I used ...

  3. selenium webdriver学习(一)

    package baidu; import java.io.File; import java.io.IOException; import junit.framework.TestCase; imp ...

  4. 数据结构——B树、B+树

    B树和B+树主要应用于外排序,对于外排序,从硬盘读取的时间要远远大于遍历树的时间,因此要想办法减少从硬盘读取的时间. B树(有时也叫B-树) M阶B树定义如下: 是一种多路搜索树(并不是二叉的):1. ...

  5. 解压zip文件中文文件名乱码问题

    主要原因是,在windows下压缩文件时,是以系统的默认编码(gbk,gb18030)来压缩,zip文件并没有声明编码的格式,因此,linux下解压缩时,也会使用系统默认的格式(utf-8)解压缩,编 ...

  6. 【leetcode】Copy List with Random Pointer (hard)

    A linked list is given such that each node contains an additional random pointer which could point t ...

  7. 【leetcode】Candy(hard) 自己做出来了 但别人的更好

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  8. ASP.net绑定文本框Enter事件到按钮 ASP.NET执行后台执行JS方法

    txtAccountBarcode.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if (( ...

  9. rabbitmq_config

    https://github.com/rabbitmq/rabbitmq-server/blob/stable/docs/rabbitmq.config.example   %% ---------- ...

  10. 自己动手编译hadoop-2.5.2源码

    搭建环境:Centos x 6.5  64bit (后来:我才知道原来官网上发布的就是64位的,不过这个对我来说是个学习过程,对以后进行其他平台编译的时候有帮助!) 1.安装JDK 我这里用的是64位 ...