-1

The Error: "Cannot assign value of type 'CLLocationDegrees' (aka 'Double') to type 'Int'"

I am getting an error that says "Cannot assign value of type 'CLLocationDegrees' (aka 'Double') to type 'Int'". Below is an image of the error. When I make the recommended change (shown the second picture) it makes latitude, longitude, and speed an integer (whole number). I need the number to be as accurate as possible, so an integer is not accurate enough. Please reply if you have any questions or have a fix.

The first picture with the error

The second picture with the recommended fix

username
  • 79
  • 10
  • The problem is that you declared your variables wrong. You made `latitudeCurrentLocation` etc. an Int. – matt Apr 18 '18 at 23:08
  • What did you try to do? Did you search before you ask? possible duplicate of https://stackoverflow.com/questions/42364537/how-to-fix-cannot-assign-value-of-type-cllocationdegrees-aka-double-to-ty – Phd. Burak Öztürk Apr 19 '18 at 00:01
  • 1
    Don't post pictures of code. Post the actual code, and quote the error you're getting. – Duncan C Apr 19 '18 at 00:53
  • The recommended fix from Xcode is wrong. You should declare your `latitude` and `longitude` variables as CLLocationDegrees type, and `speedCurrentLocation` as a `Double` – Duncan C Apr 19 '18 at 00:55
  • @BurakÖztürk I don't think it is it that one seems slightly different. That one was with the Google Maps API. The problem was the same, but the solution was not. Thanks for understanding. – username Nov 07 '18 at 14:39

1 Answers1

0

You should declare your variables as CLLocationDegrees type:

var latitudeCurrentLocation: CLLocationDegrees = 0.0
var longitudeCurrentLocation: CLLocationDegrees = 0.0
var speedCurrentLocation: CLLocationDegrees = 0.0
Kosuke Ogawa
  • 7,383
  • 3
  • 31
  • 52
  • Thanks. This worked, but I had to make a few changes. I was using a variable, so I had to make it `var latitudeCurrentLocation: CLLocationDegrees = 0.0` and defined the variable as `latitudeCurrentLocation = location.coordinate.latitude`. Then do this for the rest of the variables. It would be great if you could update your answer for other people looking at this. – username Apr 19 '18 at 15:20