【问题标题】:How to Fix: Cannot assign value of type 'CLLocationDegrees' (aka 'Double') to type 'Float!' in Swift 3如何修复:无法将“CLLocationDegrees”(又名“Double”)类型的值分配给“Float!”在斯威夫特 3
【发布时间】:2017-07-10 21:52:27
【问题描述】:

我从我的谷歌地图得到一个坐标,我想将它分配给一个浮点变量,但它显示了这个错误:

无法将“CLLocationDegrees”(又名“Double”)类型的值分配给类型 '漂浮!'

func markerButtonClicked(sender:MapButton) {
 let coord = self.getCenterCoordinate()
    let addressObj = Address()
    addressObj.latitude  = coord.latitude 
    addressObj.longitude = coord.longitude
}
func getCenterCoordinate() -> (CLLocationCoordinate2D) {
    let location = CGPoint(x:self.mView.bounds.size.width/2,y:self.mView.bounds.size.height/2)
    let coord = self.mView.projection .coordinate(for: location)
    return coord
}    

class Address: NSObject {
    var latitude:Float!
    var longitude:Float!
}

【问题讨论】:

  • 改变这个 var latitude: Double!, var longitude: Double!

标签: ios swift location coordinate cllocationcoordinate2d


【解决方案1】:

将你的值转换为浮点数,然后赋值

addressObj.latitude  = Float(coord.latitude)
addressObj.longitude = Float(coord.longitude)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 2017-03-24
    • 1970-01-01
    相关资源
    最近更新 更多