swfit地图定位 (二)

来源:互联网 发布:淘宝乐器店客户定位 编辑:程序博客网 时间:2024/06/10 05:56
import UIKitimport CoreLocationclass ViewController: UIViewController {    lazy var locationM: CLLocationManager = {       let locationM = CLLocationManager()        locationM.delegate = self        if #available(iOS 8.0, *) {            locationM.requestAlwaysAuthorization()        }        locationM.desiredAccuracy = kCLLocationAccuracyBest        return locationM    }()        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)    {        // 定位: 标准定位服务 (gps/wifi/蓝牙/基站)//        locationM.startUpdatingLocation()                // 显著位置变化的服务(基站进行定位, 电话模块)//        locationM.startMonitoringSignificantLocationChanges()                if #available(iOS 9.0, *) {            //  不能与 startUpdatingLocation同时使用            // 必须实现代理的定位失败的方法            locationM.requestLocation()        }    }}extension ViewController: CLLocationManagerDelegate {    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {        print("已经获取到位置信息")    }        func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {        print("定位失败")//        manager.startUpdatingLocation()    }}

0 0
原创粉丝点击