I have the following so far, but can\'t figure out a tidy way to get the direction letters in without a bunch of messy if statements. Any ideas? Ideally I\'d like to extend
Regarding to Alex's answer, here is a solution in Swift 3 with an output tuple. It returns the coordinates in a tuple.
Furthermore, it really extends the class CLLocationDegrees and doesn't require an extra parameter.
import MapKit
extension CLLocationDegrees {
func degreeRepresentation() -> (northOrEast: Bool, degrees: Int, minutes: Int, seconds: Int) {
var inputSeconds = Int(self * 3600)
let inputDegrees = inputSeconds / 3600
inputSeconds = abs(inputSeconds % 3600)
let inputMinutes = inputSeconds / 60
inputSeconds %= 60
return (inputDegrees > 0, abs(inputDegrees), inputMinutes, inputSeconds)
}
}