Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios swift 4谷歌地图-如何使用手势更新标记位置.position_Ios_Swift_Google Maps_Google Maps Markers_Swift4 - Fatal编程技术网

Ios swift 4谷歌地图-如何使用手势更新标记位置.position

Ios swift 4谷歌地图-如何使用手势更新标记位置.position,ios,swift,google-maps,google-maps-markers,swift4,Ios,Swift,Google Maps,Google Maps Markers,Swift4,在viewDidLoad中,我将GestureRecognitors添加到mapView中,并将ConsumagestureInview设置为true 在handleTap方法中,我将接触点转换为latLng,然后使用latLng设置标记位置,但标记移动速度非常慢 self.mapView.settings.consumesGesturesInView = true for gestureRecognizer in self.mapView.gestureRecognizers! {

viewDidLoad
中,我将
GestureRecognitors
添加到
mapView
中,并将
ConsumagestureInview设置为true
在handleTap方法中,我将接触点转换为latLng,然后使用latLng设置标记位置,但标记移动速度非常慢

self.mapView.settings.consumesGesturesInView = true
for gestureRecognizer in self.mapView.gestureRecognizers! {
                                gestureRecognizer.addTarget(self, action: #selector(MapViewController.handleTap(_:)))
}

      @objc func handleTap(_ sender: UITapGestureRecognizer) {
                var allMarkers = markers
                if(sender.numberOfTouches == 1){
                    var positions = CGPoint()
                    var newPosition = CLLocationCoordinate2D()
                    let currentZoom = self.mapView.camera.zoom

                    switch (sender.state){
                    case .began:
                        positions = sender.location(in: self.mapView)
                        newPosition = self.mapView.projection.coordinate(for: positions)
                        let ind = self.getNearbymarkers(position: newPosition,markers:allMarkers)
                        allMarkers[ind].position = newPosition
                        self.mapView.settings.scrollGestures = false
                        mapView(self.mapView, didBeginDragging: allMarkers[ind])
                        self.mapView.settings.scrollGestures = true
                        break
                    case .ended:
                        positions = sender.location(in: self.mapView)
                        newPosition = self.mapView.projection.coordinate(for: positions)
                        let ind = self.getNearbymarkers(position: newPosition,markers:allMarkers)
                        print(ind)
                        allMarkers[ind].position = newPosition
                        self.mapView.settings.scrollGestures = false
                        mapView(self.mapView, didEndDragging: allMarkers[ind])
                        self.mapView.settings.scrollGestures = true
                        break
                    case .changed:
                        positions = sender.location(in: self.mapView)
                        newPosition = self.mapView.projection.coordinate(for: positions)
                        let ind = self.getNearbymarkers(position: newPosition,markers:allMarkers)
                        print(ind)
                        allMarkers[ind].position = newPosition
                        self.mapView.settings.scrollGestures = false
                        mapView(self.mapView, didDrag: allMarkers[ind])
                        self.mapView.settings.scrollGestures = true
                        break
                    default:
                        break
                    }
            }
        }
问题是当执行此行时,标记呈现为慢速
allMarkers[ind].position=newPosition

就像我的手指移动得很快,那么标记看起来就像在手指后面移动一样

根据我的经验,GM框架中没有简单的内置解决方案。不幸的是,
GMSMarker
对象允许您跟踪的唯一交互事件(几乎没有延迟)是一个简单的点击,它会在mapView的委托中触发相应的回调。如果您想要更复杂的东西,您必须在执行拖放操作时,在地图上方放置您自己的自定义标记视图来实现这些东西。以下是算法:

1) 在地图视图中添加
UIPangestureRecognitor
。将其委托设置为解决与mapView内置手势识别器的冲突

2) 开始平移时,在
手势识别器中应开始
确定用户是将平移应用于地图还是标记。如果要标记,允许panGR开火(
返回true

3) 隐藏
GMSMarker
要移动的对象(将不透明度设置为零或仅从地图中删除)

4) 在手指位置下插入自定义独立MarkerView(在视觉上与步骤3中移除的MarkerView重复)

5) 使用panGR的更新移动此自定义视图


6) 释放手指时,将自定义MarkerView替换为最终手指位置上的
GMSMarkerView
,以便将其固定到地图背面。

我想移动类似PangestureRecognitor的标记