How to convert latitude and longitude to float value in swift

I tried the code below: but it shows that the error cannot convert the value of type float to the expected argument type CLLocation degrees (aka Double)

let lat = self.mallData.valueForKey("lat") as! Float let lon = self.mallData.valueForKey("lon") let mapLocation : CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat, lon) 
+5
source share
2 answers

CLLocationCoordinate2DMake supports Double values. But you are converting lat and lon to Float .

Try converting lat and lon to Double .

+3
source

Please check this answer

  let lat = self.mallData.valueForKey("lat") let lon = self.mallData.valueForKey("lon") let latDoubleValue = lat?.doubleValue let longDoubleValue = lon?.doubleValue let locationCoord : CLLocationCoordinate2D = CLLocationCoordinate2DMake(latDoubleValue!, longDoubleValue!) 
-3
source

All Articles