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.
If I could get a hold of the underlying view of the GMSMarker, I could intercept the Touch events. Anybody tried this?
// To add the marker to the map, call setMap(); marker.setMap(map);
By default, marker is not draggable. marker. draggable=YES; You have to press-and-hold on the marker before it will begin dragging.
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<GMSMapViewDelegate> ...
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);
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With