1
我想在我從geofire數據庫獲取的位置上顯示註釋,但即使在編寫代碼並沒有收到任何錯誤之後,地圖上也不會顯示註釋。 我的變量是無法在geofire getlocation回調中顯示註釋
var vendorStore: Dictionary<String,Int>
我在viewDidLoad中
for (key,_) in KeyValue{
geoFireKeyValue.getLocationForKey(key, withCallback: { (location, error) in
if (error != nil) {
print("An error occurred getting the location for \"firebase-hq\": \(String(describing: error?.localizedDescription))")
} else if location != nil {
let annotation = MKPointAnnotation()
self.lat = (location?.coordinate.latitude)!
self.long = (location?.coordinate.longitude)!
annotation.coordinate = CLLocationCoordinate2D(latitude: self.lat, longitude: self.long)
self.mapView.addAnnotation(annotation)
self.mapView.showAnnotations(self.mapView.annotations, animated: true)
} else {
print("GeoFire does not contain a location for \"firebase-hq\"")
}
})
}
我成功地獲得在打印語句的經度和緯度,以及,但仍然沒有註釋顯示出來的代碼。我嘗試將其他代碼移動到for循環之外(僅用於檢查是否顯示任何註釋),並使用一些硬編碼的經緯度座標併成功顯示註釋。但是,當它們在循環內的geofire函數中設置時,它們仍未顯示出來(即使硬編碼值也不會在geofire函數外部的循環中顯示)。所以請幫助我解決這個問題。
問題仍未解決 –