GoogleMaps Framework Reference

GMSMapViewDelegate

@protocol GMSMapViewDelegate <NSObject>

Delegate for events on GMSMapView.

  • Called before the camera on the map changes, either due to a gesture, animation (e.g., by a user tapping on the “My Location” button) or by being updated explicitly via the camera or a zero-length animation on layer.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, willMove gesture: Bool)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView willMove:(BOOL)gesture;

    Parameters

    mapView

    The map view that was tapped.

    gesture

    If YES, this is occurring due to a user gesture.

  • Called repeatedly during any animations or gestures on the map (or once, if the camera is explicitly set). This may not be called for all intermediate camera positions. It is always called for the final position of an animation or gesture.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didChangeCameraPosition:(nonnull GMSCameraPosition *)position;
  • Called when the map becomes idle, after any outstanding gestures or animations have completed (or after the camera has been explicitly set).

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        idleAtCameraPosition:(nonnull GMSCameraPosition *)position;
  • Called after a tap gesture at a particular coordinate, but only if a marker was not tapped. This is called before deselecting any currently selected marker (the implicit action for tapping on the map).

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;
  • Called after a long-press gesture at a particular coordinate.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didLongPressAt coordinate: CLLocationCoordinate2D)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;

    Parameters

    mapView

    The map view that was tapped.

    coordinate

    The location that was tapped.

  • Called after a marker has been tapped.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool

    Objective-C

    - (BOOL)mapView:(nonnull GMSMapView *)mapView
        didTapMarker:(nonnull GMSMarker *)marker;

    Parameters

    mapView

    The map view that was tapped.

    marker

    The marker that was tapped.

    Return Value

    YES if this delegate handled the tap event, which prevents the map from performing its default selection behavior, and NO if the map should continue with its default selection behavior.

  • Called after a marker’s info window has been tapped.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didTapInfoWindowOfMarker:(nonnull GMSMarker *)marker;
  • Called after a marker’s info window has been long pressed.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didLongPressInfoWindowOf marker: GMSMarker)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didLongPressInfoWindowOfMarker:(nonnull GMSMarker *)marker;
  • Called after an overlay has been tapped.

    This method is not called for taps on markers.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didTapOverlay:(nonnull GMSOverlay *)overlay;

    Parameters

    mapView

    The map view that was tapped.

    overlay

    The overlay that was tapped.

  • Called after a POI has been tapped.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didTapPOIWithPlaceID placeID: String, name: String, location: CLLocationCoordinate2D)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didTapPOIWithPlaceID:(nonnull NSString *)placeID
                        name:(nonnull NSString *)name
                    location:(CLLocationCoordinate2D)location;

    Parameters

    mapView

    The map view that was tapped.

    placeID

    The placeID of the POI that was tapped.

    name

    The name of the POI that was tapped.

    location

    The location of the POI that was tapped.

  • Called when a marker is about to become selected, and provides an optional custom info window to use for that marker if this method returns a UIView.

    If you change this view after this method is called, those changes will not necessarily be reflected in the rendered version.

    The returned UIView must not have bounds greater than 500 points on either dimension. As there is only one info window shown at any time, the returned view may be reused between other info windows.

    Removing the marker from the map or changing the map’s selected marker during this call results in undefined behavior.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView?

    Objective-C

    - (nullable UIView *)mapView:(nonnull GMSMapView *)mapView
                markerInfoWindow:(nonnull GMSMarker *)marker;

    Return Value

    The custom info window for the specified marker, or nil for default

  • Called when -mapView:markerInfoWindow: returns nil. If this method returns a view, it will be placed within the default info window frame. If this method returns nil, then the default rendering will be used instead.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -> UIView?

    Objective-C

    - (nullable UIView *)mapView:(nonnull GMSMapView *)mapView
              markerInfoContents:(nonnull GMSMarker *)marker;

    Parameters

    mapView

    The map view that was pressed.

    marker

    The marker that was pressed.

    Return Value

    The custom view to display as contents in the info window, or nil to use the default content rendering instead

  • Called when the marker’s info window is closed.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didCloseInfoWindowOf marker: GMSMarker)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didCloseInfoWindowOfMarker:(nonnull GMSMarker *)marker;
  • Called when dragging has been initiated on a marker.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didBeginDragging marker: GMSMarker)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didBeginDraggingMarker:(nonnull GMSMarker *)marker;
  • Called after dragging of a marker ended.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didEndDragging marker: GMSMarker)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didEndDraggingMarker:(nonnull GMSMarker *)marker;
  • Called while a marker is dragged.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didDrag marker: GMSMarker)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didDragMarker:(nonnull GMSMarker *)marker;
  • Called when the My Location button is tapped.

    Declaration

    Swift

    optional func didTapMyLocationButton(for mapView: GMSMapView) -> Bool

    Objective-C

    - (BOOL)didTapMyLocationButtonForMapView:(nonnull GMSMapView *)mapView;

    Return Value

    YES if the listener has consumed the event (i.e., the default behavior should not occur), NO otherwise (i.e., the default behavior should occur). The default behavior is for the camera to move such that it is centered on the device location.

  • Called when the My Location Dot is tapped.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didTapMyLocation location: CLLocationCoordinate2D)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didTapMyLocation:(CLLocationCoordinate2D)location;

    Parameters

    mapView

    The map view that was tapped.

    location

    The location of the device when the location dot was tapped.

  • Called when tiles have just been requested or labels have just started rendering.

    Declaration

    Swift

    optional func mapViewDidStartTileRendering(_ mapView: GMSMapView)

    Objective-C

    - (void)mapViewDidStartTileRendering:(nonnull GMSMapView *)mapView;
  • Called when all tiles have been loaded (or failed permanently) and labels have been rendered.

    Declaration

    Swift

    optional func mapViewDidFinishTileRendering(_ mapView: GMSMapView)

    Objective-C

    - (void)mapViewDidFinishTileRendering:(nonnull GMSMapView *)mapView;
  • Called when map is stable (tiles loaded, labels rendered, camera idle) and overlay objects have been rendered.

    Declaration

    Swift

    optional func mapViewSnapshotReady(_ mapView: GMSMapView)

    Objective-C

    - (void)mapViewSnapshotReady:(nonnull GMSMapView *)mapView;
  • Called every time map capabilities are changed.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didChangeMapCapabilities mapCapabilities: GMSMapCapabilityFlags)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didChangeMapCapabilities:(GMSMapCapabilityFlags)mapCapabilities;

    Parameters

    mapView

    The map view where mapCapabilities was changed.

    mapCapabilities

    Flags representing the capabilities on the map currently.

  • Called after features in a data-driven styling feature layer have been tapped.

    All features overlapping with the point being tapped will be included. If the features belong to different feature layers, this method will be called multiple times (once for each individual feature layer).

    There is no guaranteed order between events on different feature layers, or between events on feature layers and other entities on the base map.

    Declaration

    Swift

    optional func mapView(_ mapView: GMSMapView, didTap features: [any Feature], in featureLayer: FeatureLayer<any Feature>, atLocation location: CLLocationCoordinate2D)

    Objective-C

    - (void)mapView:(nonnull GMSMapView *)mapView
        didTapFeatures:(nonnull NSArray<id<GMSFeature>> *)features
        inFeatureLayer:(nonnull GMSFeatureLayer *)featureLayer
            atLocation:(CLLocationCoordinate2D)location;

    Parameters

    mapView

    The map view that was tapped.

    features

    Array of all features being clicked in the layer.

    featureLayer

    The feature layer containing the feautre.

    location

    The location of the actual tapping point.