iOS Google地图标记拖动事件

时间:2014-12-10 09:21:29

标签: ios google-maps-sdk-ios

我正在使用谷歌地图SDK构建iOS应用程序。当用户执行longPressAtCoordinate时,我可以在地图上添加一些标记。我的问题是,当我试图拖动一个标记时,diiLongPressAtCoordinate在didBeginDraggingMarker之前触发,因此也添加了一个新标记。

-(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
    }

1 个答案:

答案 0 :(得分:6)

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

- (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");
}