【发布时间】:2019-08-11 13:55:18
【问题描述】:
我正在尝试使用 Google Maps API 和 Firebase 制作 iOS 应用。它应该在地图上显示许多标记。
地图部分运行良好。但是,我想从 Firebase 实时数据库中检索位置数据(纬度、经度),然后放入 marker.position。 (那么它应该创建一个标记,对吧?)
很多天了,我仍然无法显示标记(但我可以从 Firebase 数据库打印正确的数据)。
ref = Database.database().reference()
ref.child("locations").observeSingleEvent(of: .value) { (snapshot) in
if snapshot.exists() {
if let location = snapshot.value as? [String:Any] {
for eachLocation in location {
print("Location: \(eachLocation)")
if let locationCoordinate = eachLocation.value as? [String: Any] {
if let lavLatitude = locationCoordinate["latitude"] as? Double {
if let lavLongitude = locationCoordinate["longitude"] as? Double {
print(lavLatitude)
print(lavLongitude)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(lavLatitude, lavLongitude)
marker.map = mapView
}
}
}
}
}
}
}
我来自 Github 的代码参考:appsmall/Map-Demo。
当我复制并替换我的 GoogleService-Info.plist 时,这真的很奇怪。我的应用可以显示他的 Firebase 数据库中的标记!
我想知道我的数据库中有什么问题:Screenshot。
当然,我在这里搜索并尝试了许多不同的解决方案,但仍然不起作用,如果您需要更多信息,请告诉我,谢谢!
【问题讨论】:
-
你的标记有
iconView(marker.iconView = someView)吗? -
没有marker.iconView,只是普通的谷歌地图标记
-
尝试用这个
marker.position = CLLocationCoordinate2D(latitude: lavLatitude, longitude: lavLongitude)替换你的标记位置 -
不,我试过了。
-
我认为问题出在 firebase 数据库......
标签: ios swift firebase google-maps google-maps-markers