A way to implement the drag & drop functionality in the new Google Maps SDK for iOS.
Before you can compile the project you have to create a new file called
GMPrivateMapsKey.m and add it to the project. This file has to contain your API Key for the Google Maps SDK.
#import "GMPrivateMapsKey.h" NSString *const kPrivateMapsAPIKey = @"<YOUR API KEY>";
The way to receive a key is descriped at: https://developers.google.com/maps/documentation/ios/start
GMViewController creates an instance of
GMDraggableMarkerManager and sets itself as the delegate in order to be notified of drag events.
A long press on the marker enables you to drag it around and set it to another position.
To initialize the drag & drop functionality you have to do import the
GMDraggableMarkerManager.hin your UIViewController displaying the map:
Create a property for the
@property (strong, nonatomic, readwrite) GMDraggableMarkerManager *draggableMarkerManager;
After the initialization of the Google Maps View you have to initialize the
self.draggableMarkerManager = [[GMDraggableMarkerManager alloc] initWithMapView:self.googleMapsView delegate:self];
To receive callbacks when the marker was dragged, the dragging startet/ended or just when there was a long press on a coordinate you have to conform the
At the moment the following optional methods are available:
- (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker;
- (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker;
- (void)mapView:(GMSMapView *)mapView didDragMarker:(GMSMarker *)marker;
- (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;
google-maps-sdk-ios-drag-drop - Copyright (C) 2015 Robert Weindl (firstname.lastname@example.org)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.