Search code examples
swiftinttype-conversioncllocationcoordinate2d

Convert CLLocationCoordinate2D to double or int swift


how would I convert a CLLocationcoordiante to a double so that I can perorrm arithmetic on it and compare coordinates using their size? In (swift for ios)


Solution

  • CLLocationCoordinate2D is struct of latitude and longitude both defined as CLLocationDegrees which itself is a typealias of double.

    The following code creates a location in code, but it could also be supplied by a MapKit function:

    var location = CLLocationCoordinate2D(latitude: 10.30, longitude: 44.34)
    

    You now can access the values by calling location.latitude and location.longitude.