Draggable marker with Google Maps SDK for iOS

后端 未结 4 1362
鱼传尺愫
鱼传尺愫 2021-02-05 13:33

Has anybody figured out how to implement draggable markers with the new Google Maps SDK for iOS? The API does not provide it natively, yet. Feature request is already submitted.

4条回答
  •  野性不改
    2021-02-05 14:09

    As of today, You don't need to use external classes, just make your markers "draggable"

    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];
    

    And implement the respective delegate

    @interface YourController: UIViewController ...
    

    Set your delegate

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

    Then you can handle each marker event, ie:

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

提交回复
热议问题