geo*_*eok 1 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
}
Run Code Online (Sandbox Code Playgroud)
我通过创建一个名为isDragging的布尔属性并根据是否正在拖动标记来更改它的值来解决此问题.
- (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker
{
self.isDragging = YES;
}
- (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker
{
self.isDragging = NO;
}
Run Code Online (Sandbox Code Playgroud)
然后我验证是否在检测到长按时拖动标记:
- (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate
{
if (self.isDragging) {
return;
}
NSLog(@"Long press detected");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1276 次 |
| 最近记录: |