gpt4 book ai didi

ios - 如何将字符串转换为 CLLocationDegrees Swift 2

转载 作者:可可西里 更新时间:2023-11-01 00:51:03 24 4
gpt4 key购买 nike

我正在尝试转换从 Firebase 检索的字符串并将其添加为 Google map 上的多个注释。不幸的是,我的应用程序在执行当前代码时崩溃:

ref = FIRDatabase.database().reference()
ref.child("Locations").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
let lat = (snapshot.value!["Latitude"] as! NSString).doubleValue
let lon = (snapshot.value!["Longitude"] as! NSString).doubleValue



let complainLoc = CLLocationCoordinate2DMake(lat, lon)

let Coordinates = CLLocationCoordinate2D(latitude: lat, longitude: lon)

})

My JSON Tree

My Code Block Which Crashes

这是我用来将数据保存到 Firebase 的代码

FIRDatabase.database().reference().child("Location").child(FIRAuth.auth()!.currentUser!.uid).setValue(["Latitude": locationManager.location!.coordinate.latitude, "Longitude": locationManager.location!.coordinate.longitude])

最佳答案

SWIFT 5

let dbLat = Double(latStr)  // Convert String to double
let dbLong = Double(longStr)

使用经纬度

let center = CLLocationCoordinate2D(latitude: dbLat! , longitude: dbLong! )

let pointAnnotation = MKPointAnnotation()
pointAnnotation.coordinate = CLLocationCoordinate2D(latitude: dbLat!, longitude:dbLong!)

关于ios - 如何将字符串转换为 CLLocationDegrees Swift 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38922258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com