//
// ViewController.swift
// Dome2test
//
// Created by 郭文亮 on 2018/11/22.
// Copyright © 2018年 finalliang. All rights reserved.
//
import UIKit
//导入定位框架 (全球卫星定位 、 蜂窝基站 、 无线网络定位)
import CoreLocation
//添加一个地理定位的代理协议CLLocationManagerDelegate
class ViewController: UIViewController , CLLocationManagerDelegate {
//框架提供的位置管理类
var locationManager:CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
//创建一个位置管理器实例
locationManager = CLLocationManager()
//设置位置管理器的代理对象 为当前视图控制器
locationManager.delegate = self
//给位置管理器对象 设置最佳的精度级别
locationManager.desiredAccuracy = kCLLocationAccuracyBest
//设置没1000m调用委托方法
locationManager.distanceFilter = 1000.0
//启动位置管理器
locationManager.startUpdatingLocation()
}
//代理方法 用来响应位置更新的时间
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//获得定位设备返回的定位数组 并获得数组中的第一个元素
let location:CLLocation = locations[0]
//获得元素中的经纬度数值
let latitude = location.coordinate.latitude
let longitude = location.coordinate.longitude
print("latitude :\(latitude)")
print("longitude:\(longitude)")
//停止定位服务
locationManager.stopUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}