gpt4 book ai didi

ios - 从 Firebase Swift 检索双数字时出现问题

转载 作者:行者123 更新时间:2023-11-30 12:05:29 25 4
gpt4 key购买 nike

我目前正在开展餐厅项目,通过按餐厅 View Controller 上的按钮,我可以在谷歌地图( map View Controller )上查看餐厅的位置。为了将纬度和经度放入我的 map 代码中,我在从 Firebase 检索 Double 数字时遇到问题。每当我尝试打印它们时,我都会收到此错误“ fatal error :在展开可选值 (lldb) 时意外发现 nil”

GMSServices.provideAPIKey("AIzaSyRQKeLyKH5CsrDPpPsjy7nYqudEbqXmQS2")
let ref = Database.database().reference().child("amsterdam")
ref.queryOrdered(byChild: "name").queryEqual(toValue: self.appDelegate.selectedBarName).observe(.value) { (snapshot) in
for child in snapshot.children{
let snap = child as! DataSnapshot
let mapSnap = snap.childSnapshot(forPath: "map")
if let snapDict = mapSnap.value as? [String:AnyObject]{
let dictValues = [AnyObject](snapDict.values)
for each in dictValues{
let latitude = each["map_latitude"] as! Double
let longitude = each["map_longitude"] as! Double

print(latitude)
print(longitude)
let camera = GMSCameraPosition.camera(withLatitude: latitude, longitude: longitude, zoom: 6.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
self.view = mapView
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
marker.map = mapView
}
}
}
}
}

最佳答案

我认为问题在于从每个中获取值(value)。尝试使用此行获取 each 作为字典对象的值。

let latitude = each.object(forKey:"map_latitude") as! Double

关于ios - 从 Firebase Swift 检索双数字时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46723545/

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