简体   繁体   English

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

[英]How to convert Latitude and longitude to float value in swift

I have tried the below code : but it shows error cannot convert value of type float to expected argument type CLLocation degrees(aka Double) 我已经尝试了下面的代码:但它显示错误无法将float类型的值转换为预期的参数类型CLLocation degrees(又名Double)

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



    let mapLocation : CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat, lon)

The CLLocationCoordinate2DMake supports Double values. CLLocationCoordinate2DMake支持Double值。 But you are converting lat and lon to Float . 但是你将latlon转换为Float

Try converting Lat and Lon to Double . 尝试将LatLon转换为Double

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM