gpt4 book ai didi

ios - 如何在 Google MapView iOS 中设置固定标记位置

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

这里我正在使用 GoogleMapKit 处理 mapKitView ,这里我想在用户使用 didBeginDragging 拖动标记时执行此操作, didDraggingdidEndDragging并在屏幕的任意位置释放标记。我发现了一个帮助内容来修复屏幕中的标记 Hugo Jordao的答案,但这仅适用于屏幕中心的固定标记位置。那么我如何在任何特定的屏幕点设置标记??

  • 拖动方式
    func mapView(_ mapView: GMSMapView, didEndDragging marker: GMSMarker) {
if marker == mapMarker{
self.markerPosition = GMSCameraPosition(latitude: marker.position.latitude, longitude: marker.position.longitude, zoom: 5.0)
print("End Dragging")
}
}
  • 将标记中心设置为屏幕
 func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
if self.markerPosition == nil{
mapMarker.position = position.target
}else{
mapMarker.position = self.markerPosition.target
}
}

最佳答案

回答我自己的问题。

第一个添加的变量用于在CGPoint中存储位置值

var markerPosition : CGPoint!
  • 然后将 CLLocationCooperative2D 位置值转换为 CGPoint 并存储到 didEndDragging mark 方法中的 markerPosition 中。
 func mapView(_ mapView: GMSMapView, didEndDragging marker: GMSMarker) {
if marker == mapMarker{

self.markerPosition = self.mapView.projection.point(for: CLLocationCoordinate2D(latitude: marker.position.latitude, longitude: marker.position.longitude))

print("End Dragging")
}
}
  • 之后,根据CGPoint值在任何屏幕点设置GMSMarker位置MAPView
 func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
if self.markerPosition == nil{
//To set pin into the center of mapview
mapMarker.position = position.target

}else{
//To set pin into the any particular point of the screen on mapview
let coordinate = self.mapView.projection.coordinate(for: self.markerPosition)
mapMarker.position = coordinate
}
}

关于ios - 如何在 Google MapView iOS 中设置固定标记位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57658954/

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