import UIKit
import CoreLocation
class 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?){
locationM.startUpdatingLocation()
// let loc1 = CLLocation(latitude: 21.123, longitude: 121.345)
// let loc2 = CLLocation(latitude: 22.123, longitude: 121.345)
// let distance: CLLocationDistance = loc1.distance(from: loc2)
// print(distance)//110725.220968516
}
}
extension ViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
swift 地图定位(三)
最新推荐文章于 2023-03-31 10:19:39 发布