3

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

无法将“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!
}
4

1 回答 1

6

将您的值转换为浮点数,然后分配

addressObj.latitude  = Float(coord.latitude)
addressObj.longitude = Float(coord.longitude)
于 2017-02-21T10:23:40.347 回答