当我点击确实点击了标记时,它会为我提供当前标记,但是添加新标记时它不会追加,而是在添加了较新的子项之后将其追加。
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
DispatchQueue.main.async(execute: {
self.infoWindow.removeFromSuperview()
self.locationMarker = nil
self.locationMarker = marker
var markerData: NSDictionary?
if let data = marker.userData! as? NSDictionary {
markerData = data
}
print(markerData as Any)
self.infoWindow.markData = markerData
self.infoWindow = self.loadNiB()
if let keyData = markerData?["key"] {
self.keyDataStored = keyData
markerData = nil
}
guard let location = self.locationMarker?.position else {
print("locationMarker is nil")
return
}
self.infoWindow.center = mapView.projection.point(for: location)
self.infoWindow.center.y = self.infoWindow.center.y - self.sizeForOffset(view: self.infoWindow)
UIView.transition(with: self.view, duration: 0.25, options: [.transitionCrossDissolve], animations: {
self.view.addSubview(self.infoWindow)
}, completion: nil)
return false
}
print(markerData as Any)的结果是
Optional({
Vote = 0;
key = "-LVIje0829RH0EkwUuiz";
latitude = "37.33233141";
longitude = "-122.0312186";
})
针对大孩子
但是,如果我添加了新的孩子,则用xchild标记它,结果是
Optional({
latitude = "37.49707671";
longitude = "-122.31324792";
})
如果我再次添加了新孩子,我们假设它是ychild,那么xchild将被更新并成为
Optional({
Vote = 0;
key = "-LVICnM6l5TMdsqkpP70";
latitude = "37.49707671";
longitude = "-122.31324792";
})
并且ychild会丢失投票和关键,直到添加新的