Reputation: 94
I am trying to covert the number of magneticHeading that I see, from 0 to 360, into radians so I can use CGPoint. However this code throws an error.
//Code to move on the X plane
let heading = self!.locManager.heading
let MagHeading = (heading?.magneticHeading)! * M_PI/180 //error
How can I covert this CLLocation value I get from the heading into a float so I can turn it into radians? The error is that heading is nil. Yet without the conversion it still produces values
Upvotes: 0
Views: 176
Reputation: 79686
Actual problem and your question are absolutely different. You need to handle optional variable there... but you mentioned conversion between double/float to radian
try this... at least your error will be gone.
if let heading = self.locManager.heading {
let MagHeading = (heading.magneticHeading) * M_PI/180
print("MagHeading - \(MagHeading)")
} else {
print("heading is nil")
}
Upvotes: 1