CLLocationDistance conversion

后端 未结 5 900
面向向阳花
面向向阳花 2021-01-12 02:51

i have distance in a variable of type CLLocationDistance i need to convert it in a integer variable how can i do it

i have use

CLLocationDistance kil         


        
5条回答
  •  心在旅途
    2021-01-12 03:29

    SWIFT 4

    Late to this party, but you can also create an extension like this:

    CLLocationDistance.swift

    import UIKit
    import CoreLocation
    
    extension CLLocationDistance {
        func inMiles() -> CLLocationDistance {
            return self*0.00062137
        }
    
        func inKilometers() -> CLLocationDistance {
            return self/1000
        }
    }
    

    You could call it as follow:

    distance.inKilometers()
    

    I hope this helps anyone stumbling on this!

提交回复
热议问题