如何将纬度和经度转换为swift中的浮点值

时间:2016-09-27 04:19:49

标签: ios swift mkmapview

我试过以下代码:  但它显示错误无法将float类型的值转换为预期的参数类型CLLocation degrees(又名Double)

    let lat = self.mallData.valueForKey("lat") as! Float
    let lon = self.mallData.valueForKey("lon")



    let mapLocation : CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat, lon)

2 个答案:

答案 0 :(得分:4)

CLLocationCoordinate2DMake支持Double值。但您要将latlon转换为Float

尝试将LatLon转换为Double

答案 1 :(得分:-3)

请检查此答案

    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!)