//  DTOneViewController.swift

//  Mapper-JSON

//

//  Created by kcl on 16/8/8.

//  Copyright © 2016年 kcl. All rights reserved.

//

import UIKit

import MapKit

class DTOneViewController: UIViewController {

var locationManager:CLLocationManager!

var mapView:MKMapView!

override func viewDidLoad() {

super.viewDidLoad()

self.locationManager = CLLocationManager()

self.mapView = MKMapView()

self.mapView.frame = self.view.bounds

self.mapView.delegate = self

self.mapView.userTrackingMode = .Follow

self.mapView.showsUserLocation = true

self.mapView.mapType = MKMapType.Standard

self.view.addSubview(self.mapView)

self.locationManager.requestWhenInUseAuthorization()

self.locationManager.requestAlwaysAuthorization()

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

}

func goSearch(){

let fromCoordinate = CLLocationCoordinate2D(latitude: 22.546036, longitude: 113.960423)

let tofromCoordinate = CLLocationCoordinate2D(latitude: 22.588416, longitude: 113.972166)

let fromPlaceMark = MKPlacemark(coordinate: fromCoordinate, addressDictionary: nil)

let toPlaceMark = MKPlacemark(coordinate: tofromCoordinate, addressDictionary: nil)

let fromItem = MKMapItem(placemark: fromPlaceMark)

let toItem = MKMapItem(placemark: toPlaceMark)

self.findDirectionsFrom(fromItem, destination: toItem)

}

func findDirectionsFrom(source:MKMapItem,destination:MKMapItem){

let request = MKDirectionsRequest()

request.source = source

request.destination = destination

request.transportType = MKDirectionsTransportType.Walking

request.requestsAlternateRoutes = true;

let directions = MKDirections(request: request)

//        j

directions.calculateDirectionsWithCompletionHandler { (response, error) in

if error == nil {

self.showRoute(response!)

}else{

print("trace the error \(error?.localizedDescription)")

}

}

}

func showRoute(response:MKDirectionsResponse) {

for route in response.routes {

mapView.addOverlay(route.polyline,level: MKOverlayLevel.AboveRoads)

let routeSeconds = route.expectedTravelTime

let routeDistance = route.distance

print("distance between two points is \(routeSeconds) and \(routeDistance)")

}

}

}

extension DTOneViewController:MKMapViewDelegate,CLLocationManagerDelegate {

func mapView(mapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation) {

let lat = 0.005

let lon = 0.005

let currentLocationSpan:MKCoordinateSpan = MKCoordinateSpanMake(lat, lon)

let loc:CLLocationCoordinate2D = userLocation.coordinate

let region:MKCoordinateRegion = MKCoordinateRegionMake(loc, currentLocationSpan)

self.mapView.setRegion(region, animated: true)

goSearch()

}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

let currentlocation:CLLocation = locations.first!

print("currentlocation = \(currentlocation.coordinate.latitude) = \(currentlocation.coordinate.longitude)")

}

//    绚烂绘制polyLine

func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {

//        let render = MKPolygonRenderer(overlay: overlay)

//        render.strokeColor = UIColor.redColor()

//        render.lineWidth = 4.0

//        return render

//        if overlay is MKPolyline {

let  polylineRenderer = MKPolylineRenderer(overlay: overlay)

//      polylineRenderer.lineDashPattern = [14,10,6,10,4,10]

polylineRenderer.strokeColor = UIColor.redColor()

//      polylineRenderer.strokeColor = UIColor(red: 0.012, green: 0.012, blue: 0.012, alpha: 1.00)

polylineRenderer.fillColor = UIColor.blueColor()

polylineRenderer.lineWidth = 2.5

return polylineRenderer

//        }

//        return nil

}

}

基于swift MKMapkit 开发的地图定位导航的更多相关文章

  1. 基于Swift语言开发微信、QQ和微博的SSO授权登录代码分析

    前言 Swift 语言,怎么说呢,有一种先接受后排斥.又欢迎的感觉,纵观国外大牛开源框架或项目演示,Swift差点儿占领了多半,而国内尽管出现非常多相关技术介绍和教程,可是在真正项目开发中使用的占领非 ...

  2. Google Maps API v2密钥申请以及实现地图定位导航

    注意新建项目之前需要安装 google play  services 然后导入 通过上图方法导入sdk包下面的一个包: \adt-bundle-windows-x86\sdk\extras\googl ...

  3. java微信开发之地图定位

    页面代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...

  4. iOS开发----地图与导航--定位和位置信息获取

    要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...

  5. iOS开发系列--地图与定位

    概览 现在很多社交.电商.团购应用都引入了地图和定位功能,似乎地图功能不再是地图应用和导航应用所特有的.的确,有了地图和定位功能确实让我们的生活更加丰富多彩,极大的改变了我们的生活方式.例如你到了一个 ...

  6. 转-iOS开发系列--地图与定位

    来自: http://www.cnblogs.com/kenshincui/p/4125570.html#autoid-3-4-0 概览 现在很多社交.电商.团购应用都引入了地图和定位功能,似乎地图功 ...

  7. Android 百度地图API 定位 导航

    看看这个利用百度地图定位并实现目的地导航的Demo. 首先看实现效果:                          进 入后首先会得到当前位置,在地图上显示出来.在输入框中输入目的地后,就会在地 ...

  8. IOS开发之地图导航

    一.问题描述 现在很多的APP 都开始引入了地图和定位功能,包括一些餐饮业,团购等.他们都过定位和地图来让用户更加方便的根据自己的位置找到合适的目标,也就是说,现在地图定位已经不再是导航工具类,地图工 ...

  9. Swift项目开发实战-基于分层架构的多版本iPhone计算器-直播公开课

    Swift项目开发实战-基于分层架构的多版本iPhone计算器-直播公开课 本课程采用Q Q群直播方式进行直播,价值99元视频课程免费直播.完整的基于Swift项目实战,手把手教你做一个Swift版i ...

随机推荐

  1. javascript继承---组合式继承

    原型链继承和构造函数继承中存在着很多的缺陷,所以,使用组合式继承了进行弥补这些缺陷 //组合继承 //父函数 function a(){ this.name = "兔子只吃胡萝卜" ...

  2. vpn的实现原理

    由于公共IP的短缺,我们在组建局域网时,通常使用保留地址作为内部IP,(比如最常用的C类保留地址:192.168.0.0-192.168.255.255)这些地址是不会被互联网分配的,因此它们在互联网 ...

  3. SQL SERVER 报:由于数据移动,未能继续以 NOLOCK 方式扫描错误的解决办法。

    比如在某个表中使用 select xxx from xxx with(nolock) where xxxx 查询. 提示出错:由于数据移动,未能继续以 NOLOCK 方式扫描. 它有可能某些条件出错, ...

  4. javascript数组详解(js数组深度解析)【forEach(),every(),map(),filter(),reduce()】

    Array 对象是一个复合类型,用于在单个的变量中存储多个值,每个值类型可以不同. 创建数组对象的方法: new Array(); new Array(size); new Array(element ...

  5. iPhone与iWatch连接、控制、数据传递(Swift)

    最近在做一个项目,涉及到iPhone设备和手表传输数据.控制彼此界面跳转,在网上找了很多资料,发现国内的网站这方面介绍的不多,而国外的网站写的也不是很全,所以在这写这篇博客,给大家参考一下,望大神指点 ...

  6. MAC下Xcode配置opencv(2017.3.29最新实践,亲测可行)

    本文原创,未经同意,谢绝转载!(转载请告知本人并且经过本人同意--By Pacific-hong) 本人小硕一枚,因为专业方向图像相关,所以用到opencv,然后网上MAC下Xcode配置opencv ...

  7. Recurrent Neural Network系列4--利用Python,Theano实现GRU或LSTM

    yi作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 本文翻译自 RECURRENT NEURAL NETWORK ...

  8. Unity 3D Framework Designing(8)——使用ServiceLocator实现对象的注入

    对象的 『注入』 是企业级软件开发经常听到的术语.如果你是一个 Java 程序员,一定对注入有着深刻的映像.不管是SSH框架还是SSM框架,Spring 全家桶永远是绕不过去的弯.通过依赖注入,可以有 ...

  9. 想系统的学习一下项目管理,推荐PRINCE2

    参加pmp培训,考个pmp证书就足矣应付面试. 个人并不推荐看那些外文原版书籍,我看过一两本,水平与实用性并不是你想象的那么好,除非你是做理论研究,为了发表论文. 另一本就推荐prince2的教材,p ...

  10. 关于VO中的Attribute的问题

    对于新手来说,有些时候会遇到VO中的Attribute的各种问题; 总结如下:1,你页面上输入了值,但是点击保存之后值并不能存到数据库,这个是因为该字段在VO中不是基于EO的  2,你将一个VO中的E ...