问题
I get a coordinate from my google map and I want to assign it to a float variable, but it shows this error:
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!
}
回答1:
Convert your value to float and then assign
addressObj.latitude = Float(coord.latitude)
addressObj.longitude = Float(coord.longitude)
来源:https://stackoverflow.com/questions/42364537/how-to-fix-cannot-assign-value-of-type-cllocationdegrees-aka-double-to-ty