//  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. Ubuntu 16.04安装DB2 Express C v11.1

    欢迎和大家交流技术相关问题:邮箱: jiangxinnju@163.com博客园地址: http://www.cnblogs.com/jiangxinnjuGitHub地址: https://gith ...

  2. 【Troubleshooting Case】Unable to delete Exchange database?

    在我们日常邮件系统运维管理或实施部署变更中,经常会遇到,删除Exchange 数据库DB时,提示无法删除. ------------------– Microsoft Exchange Error - ...

  3. java 文件操作(二)---Files和Path

    自从java 7以来,引入了FIles类和Path接口.他们两封装了用户对文件的所有可能的操作,相比于java 1的File类来说,使用起来方便很多.但是其实一些本质的操作还是很类似的.主要需要知道的 ...

  4. [微信小程序]初试——成绩分析小程序问题总结

    文件类型说明 第一次打开微信小程序的开发者工具,就是下面这个样子. 好多已经存在的默认文件 .js .json .wxml .wxss 首先当然要搞懂这些文件都是干什么的 app.js是小程序的脚本代 ...

  5. 多线程图像处理中对选入DC的位图保护

    我在应用多线程加速图像处理(具体参见图像处理的多线程计算)的过程中,曾遇到过一个线程同步的问题.多线程对图像不同子块进行处理,再合成.结果发现最终不是全部子块都处理成功,有的子块好像没有被处理.而且发 ...

  6. Linux 下安装 Memcached 和 PHP 开启 Memcached 扩展

    [项目背景]:阿里云ECS服务器,Linux(centos7.2 64位),环境部署使用的是阿里云一键安装包(LAMP)等 [项目需求]:linux安装memcached 和php开启Memcache ...

  7. API的文档自动生成——基于CDIF的SOA基本能力

    当前,作为大部分移动app和云服务后台之间的标准连接方式,REST API已经得到了绝大部分开发者的认可和广泛的应用.近年来,在新兴API经济模式逐渐兴起,许多厂商纷纷将自己的后台业务能力作为REST ...

  8. centos 6.5 搭建JSP运行环境

    一.安装nginx yum install nginx #安装nginx,根据提示,输入Y安装即可成功安装 service nginx start #启动 chkconfig nginx on #设为 ...

  9. Java面试指导

    Java面试指导   想要成为合格的Java程序员或工程师到底需要具备哪些专业技能,面试者在面试之前到底需要准备哪些东西呢?本文陈列的这些内容既可以作为个人简历中的内容,也可以作为面试的时候跟面试官聊 ...

  10. Angular--学习

    18:28:34 Angular简介 AngularJS通过指令 扩展了HTML,并通过 表达式 绑定数据到HTML Angular扩展了HTML AngularJS 通过 ng-directives ...