gpt4 book ai didi

Swift Google map GMS 标记未粘贴在用户位置上

转载 作者:行者123 更新时间:2023-11-30 11:20:16 24 4
gpt4 key购买 nike

我的 GMSMarker 有问题,它似乎没有粘在用户位置上。我想将标记粘贴到用户位置本身,请检查下面的代码。

func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
UpdateService.instance.updateUserLocation(withCoordinate: position.target)
UpdateService.instance.updateContractorLocation(withCoordinate: position.target)
}

func loadContractorAnnotation() {
DispatchQueue.main.async {
DataService.instance.REF_CONTRACTOR.observeSingleEvent(of: .value, with: { (snapshot) in
if let contractorSnapshot = snapshot.children.allObjects as? [DataSnapshot] {
for contractor in contractorSnapshot {
if contractor.hasChild("coordinate") {
if contractor.childSnapshot(forPath: "contractorIsAvailable").value as? Bool == true {
if let contractorCoordinateDict = contractor.value as? Dictionary<String, Any> {
let coordinateArray = contractorCoordinateDict["coordinate"] as! NSArray
let contractorCoordinate = CLLocationCoordinate2D(latitude: coordinateArray[0] as! CLLocationDegrees , longitude: coordinateArray[1] as! CLLocationDegrees)
CATransaction.begin()
CAAnimation.init().duration = 0.5
self.contractorMarker.position = contractorCoordinate
self.contractorMarker.iconView = self.markerImageView(image: UIImage(named: "contractor-marker")!, size: CGSize(width: 30, height: 30))
self.contractorMarker.groundAnchor = CGPoint(x: 0.5, y: 0.5)
CATransaction.commit()
self.contractorMarker.map = self.mapView
}
}
}
}
}
})
}
}
// ViewDidLoad()
DataService.instance.REF_CONTRACTOR.observe(.value, with: {(snapshot) in
self.loadContractorAnnotation()
})

看起来每当我拖动 map 时,它似乎都会跟随我的谷歌地图中心的图标,而不是当我拖动谷歌地图时它只会粘在用户位置上。你可以在这个video上查看。我上传的。

最佳答案

我的错,看来我把所有东西都放在谷歌地图上了,

我从 didChangeposition 函数中移动了下面的代码行。

UpdateService.instance.updateUserLocation(withCoordinate: position.target)
UpdateService.instance.updateContractorLocation(withCoordinate: position.target)

进入这段代码。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])

关于Swift Google map GMS 标记未粘贴在用户位置上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51335719/

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