【问题标题】:Getting "Cannot assign value of type 'CLLocationDegrees' (aka 'Double') to type 'Int'" error (Swift 4)获取“无法将'CLLocationDegrees'(又名'Double')类型的值分配给'Int'类型”错误(Swift 4)
【发布时间】:2018-04-18 22:43:22
【问题描述】:

错误:“无法分配 'CLLocationDegrees' 类型的值(又名 'Double') 输入 'Int'"

我收到一条错误消息,提示“无法将 'CLLocationDegrees'(又名 'Double')类型的值分配给 'Int' 类型”。下面是错误的图像。当我进行建议的更改(显示第二张图片)时,它会将纬度、经度和速度设为整数(整数)。我需要数字尽可能准确,所以整数不够准确。如果您有任何问题或有解决办法,请回复。

The first picture with the error

The second picture with the recommended fix

【问题讨论】:

  • 问题是你声明了你的变量错误。您将latitudeCurrentLocation 等设为 Int.
  • 你试图做什么?你问之前搜索过吗? stackoverflow.com/questions/42364537/… 的可能重复项
  • 请勿发布代码图片。发布实际代码,并引用您遇到的错误。
  • Xcode 推荐的修复方法是错误的。您应该将 latitudelongitude 变量声明为 CLLocationDegrees 类型,并将 speedCurrentLocation 声明为 Double
  • @BurakÖztürk 我不认为是它看起来略有不同。那是与 Google Maps API 一起使用的。问题是一样的,但解决方案不是。感谢理解。

标签: swift mapkit


【解决方案1】:

您应该将变量声明为CLLocationDegrees 类型:

var latitudeCurrentLocation: CLLocationDegrees = 0.0
var longitudeCurrentLocation: CLLocationDegrees = 0.0
var speedCurrentLocation: CLLocationDegrees = 0.0

【讨论】:

  • 谢谢。这行得通,但我不得不做一些改变。我使用了一个变量,所以我必须将其设为var latitudeCurrentLocation: CLLocationDegrees = 0.0,并将变量定义为latitudeCurrentLocation = location.coordinate.latitude。然后对其余变量执行此操作。如果您可以为其他看到此问题的人更新您的答案,那就太好了。
猜你喜欢
  • 2017-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多