How to find out distance between coordinates?

前端 未结 10 1326
猫巷女王i
猫巷女王i 2020-12-12 15:23

I want to make it so that it will show the amount of distance between two CLLocation coordinates. Is there someway to do this without a complex math formula? If there isn\'t

10条回答
  •  难免孤独
    2020-12-12 16:02

    import UIKit
    import CoreLocation
    
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            var currentLocation = CLLocation(latitude: 23.1929, longitude: 72.6156)
            var DestinationLocation = CLLocation(latitude: 23.0504, longitude: 72.4991)
            var distance = currentLocation.distance(from: DestinationLocation) / 1000
            print(String(format: "The distance to my buddy is %.01fkm", distance))
        }
    }
    

提交回复
热议问题