3

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!
}
simonWasHere
  • 1,307
  • 11
  • 13
reza_khalafi
  • 6,230
  • 7
  • 56
  • 82

1 Answers1

7

Convert your value to float and then assign

addressObj.latitude  = Float(coord.latitude)
addressObj.longitude = Float(coord.longitude)
Milap Kundalia
  • 1,566
  • 1
  • 16
  • 24