3

Googleマップから座標を取得し、それをfloat変数に割り当てたいのですが、次のエラーが表示されます:

タイプ「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

値を float に変換してから割り当てます

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