How to find out distance between coordinates?

前端 未结 10 1274
猫巷女王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:08

    import CoreLocation
    
    //My location
    let myLocation = CLLocation(latitude: 31.5101892, longitude: 74.3440842)
    
    //My Next Destination
    let myNextDestination = CLLocation(latitude: 33.7181584, longitude: 73.071358)
    
    //Finding my distance to my next destination (in km)
    let distance = myLocation.distance(from: myNextDestination) / 1000
    

提交回复
热议问题