如何修复:无法将类型 'CLLocationDegrees'(又名 'Double')的值分配给 Swift 中的类型 'Float!' 3

How to Fix: Cannot assign value of type 'CLLocationDegrees' (aka 'Double') to type 'Float!' in Swift 3

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

Cannot assign value of type 'CLLocationDegrees' (aka 'Double') to type 'Float!'

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!
}

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

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