如何修复:无法指定'CLLocationDegrees'类型的值(也称为'Double')来键入'Float!' 在Swift 3中

rez*_*afi 2 location coordinate ios cllocationcoordinate2d swift

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

无法指定"CLLocationDegrees"类型的值(也称为"Double")来键入"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!
}
Run Code Online (Sandbox Code Playgroud)

Mil*_*lia 6

将您的值转换为float,然后分配

addressObj.latitude  = Float(coord.latitude)
addressObj.longitude = Float(coord.longitude)
Run Code Online (Sandbox Code Playgroud)