Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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谷歌地图标记拖动事件_Ios_Google Maps Sdk Ios - Fatal编程技术网

iOS谷歌地图标记拖动事件

iOS谷歌地图标记拖动事件,ios,google-maps-sdk-ios,Ios,Google Maps Sdk Ios,我正在使用谷歌地图SDK构建一个iOS应用程序。当用户长按坐标时,我可以在地图上添加一些标记。我的问题是,当我试图拖动一个标记时,diiLongPressAtCoordinate会在DidBegindRagingMarker之前触发,因此还会添加一个新的标记 -(void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker{ NSLog(@"begin dragging marker")

我正在使用谷歌地图SDK构建一个iOS应用程序。当用户长按坐标时,我可以在地图上添加一些标记。我的问题是,当我试图拖动一个标记时,diiLongPressAtCoordinate会在DidBegindRagingMarker之前触发,因此还会添加一个新的标记

-(void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker{
        NSLog(@"begin dragging marker");
    }
    - (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate (CLLocationCoordinate2D)coordinate{
        NSLog(@"did long press at mapview");
    //when user didLongPressAtCoordinate I add a new marker on the map.
    // I want to prevent the execution of this code before the didBeginDraggingMarker method
    }

我通过创建一个名为IsDraging的布尔属性并根据是否拖动标记更改其值来解决这个问题

- (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker
{
    self.isDragging = YES;
}

- (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker
{
    self.isDragging = NO;
}
然后,我验证是否在检测到长按时拖动标记:

- (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate
{
    if (self.isDragging) {

        return;
    }

    NSLog(@"Long press detected");
}