15

有人知道如何使用新的 iOS 版 Google Maps SDK 实现可拖动标记吗?API 还没有原生地提供它。功能请求已提交。

如果我能掌握 GMSMarker 的底层视图,我就可以拦截 Touch 事件。有人试过这个吗?

4

4 回答 4

19

截至今天,您不需要使用外部类,只需让您的标记“可拖动”

GMSMarker *myMarker = [[GMSMarker alloc] ...];
...
[myMarker setDraggable: YES];
// Use some kind of data to identify each marker, marker does not have 'tag' but 'userData' that is an 'id' type
[myMarker setUserData: markerId];

并实现各自的委托

@interface YourController: UIViewController<GMSMapViewDelegate> ...

设置你的代表

GMSMapView *myMapView = [[GMSMapView alloc] ...];
...
myMapView.delegate = self;

然后您可以处理每个标记事件,即:

-(void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker{
    if ([marker.userData isEqualtoString:@"xMark"])
        NSLog(@"marker dragged to location: %f,%f", marker.position.latitude, marker.position.longitude);
}
于 2014-08-22T17:46:45.703 回答
3

Hello I just implemented a drag and drop functionality for marker in the new GoogleMaps SDK for iOS. I published the code on github under the following link: https://github.com/rweindl/google-maps-sdk-ios-drag-drop

于 2013-03-09T00:37:20.417 回答
2

斯威夫特 3.0

甜的!我所要做的就是将此变量添加到我的标记中。然后,当仔细选择并按住标记片刻时,您可以拖动它。

marker.isDraggable = true  

我还没有实现代表来保存我的标记数据,但它应该是这样的。

extension MapVC : GMSMapViewDelegate {

    func mapView (_ mapView: GMSMapView, didEndDragging didEndDraggingMarker: GMSMarker) {

        print("Drag ended!")
        print("Update Marker data if stored somewhere.")

    }

}

注意:有一段时间我试图取消动画屏幕和标记在选择后浮动和动画 UP。现在我看到这是一个“功能”,因为你的手指挡住了你的视线,如果它在拖动过程中不移动屏幕,你就看不清楚。(呃!)

于 2017-10-31T16:05:51.017 回答
0

可拖动标记尚未添加到 SDK。请提交功能请求

于 2013-02-24T22:02:08.057 回答