GMSMapView Class Reference


Overview

This is the main class of the Google Maps SDK for iOS and is the entry point for all methods related to the map.

The map should be instantiated with one of the constructors -init or -initWithOptions:.

GMSMapView can only be read and modified from the main thread, similar to all UIKit objects. Calling these methods from another thread will result in an exception or undefined behavior.

Public Member Functions

(instancetype) - init
 Initializes with CGRectZero and default options.
(instancetype) - initWithOptions:
 Creates a new map view with the given options.
(instancetype) - initWithFrame:
(nullable instancetype) - initWithCoder:
(instancetype) - initWithFrame:camera:
 Builds and returns a map view, with a frame and camera target.
(instancetype) - initWithFrame:mapID:camera:
 Builds and returns a map view with a frame, map ID, and camera target.
(void) - startRendering
 Tells this map to power up its renderer.
(void) - stopRendering
 Tells this map to power down its renderer.
(void) - clear
 Clears all markup that has been added to the map, including markers, polylines and ground overlays.
(void) - setMinZoom:maxZoom:
 Sets minZoom and maxZoom.
(nullable GMSCameraPosition *) - cameraForBounds:insets:
 Build a GMSCameraPosition that presents bounds with padding.
(void) - moveCamera:
 Changes the camera according to update.
(BOOL) - areEqualForRenderingPosition:position:
 Check whether the given camera positions would practically cause the camera to be rendered the same, taking into account the level of precision and transformations used internally.
(GMSFeatureLayer
< GMSPlaceFeature * > *) 
- featureLayerOfFeatureType:
 Returns a feature layer of the specified type.
(GMSDatasetFeatureLayer *) - datasetFeatureLayerOfDatasetID:
 Returns a dataset feature layer of the specified dataset.
(void) - animateToCameraPosition:
 Animates the camera of this map to cameraPosition.
(void) - animateToLocation:
 As animateToCameraPosition:, but changes only the location of the camera (i.e., from the current location to location).
(void) - animateToZoom:
 As animateToCameraPosition:, but changes only the zoom level of the camera.
(void) - animateToBearing:
 As animateToCameraPosition:, but changes only the bearing of the camera (in degrees).
(void) - animateToViewingAngle:
 As animateToCameraPosition:, but changes only the viewing angle of the camera (in degrees).
(void) - animateWithCameraUpdate:
 Applies cameraUpdate to the current camera, and then uses the result as per animateToCameraPosition:.

Static Public Member Functions

(instancetype) + mapWithFrame:camera:
 Builds and returns a map view with a frame and camera target.
(instancetype) + mapWithFrame:mapID:camera:
 Convenience initializer to build and return a map view with a frame, map ID, and camera target.

Properties

IBOutlet id< GMSMapViewDelegatedelegate
 GMSMapView delegate.
GMSCameraPositioncamera
 Controls the camera, which defines how the map is oriented.
GMSProjectionprojection
 Returns a GMSProjection object that you can use to convert between screen coordinates and latitude/longitude coordinates.
BOOL myLocationEnabled
 Controls whether the My Location dot and accuracy circle is enabled.
CLLocation * myLocation
 If My Location is enabled, reveals where the device location dot is being drawn.
GMSMarkerselectedMarker
 The marker that is selected.
BOOL trafficEnabled
 Controls whether the map is drawing traffic data, if available.
GMSMapViewType mapType
 Controls the type of map tiles that should be displayed.
GMSMapStylemapStyle
 Controls the style of the map.
UIUserInterfaceStyle overrideUserInterfaceStyle
 Change the map to desired [UIUserInterfaceStyle](https://developer.apple.com/documentation/uikit/uiuserinterfacestyle?language=objc).
float minZoom
 Minimum zoom (the farthest the camera may be zoomed out).
float maxZoom
 Maximum zoom (the closest the camera may be to the Earth).
BOOL buildingsEnabled
 If set, 3D buildings will be shown where available.
BOOL indoorEnabled
 Sets whether indoor maps are shown, where available.
GMSIndoorDisplayindoorDisplay
 Gets the GMSIndoorDisplay instance which allows to observe or control aspects of indoor data display.
GMSUISettingssettings
 Gets the GMSUISettings object, which controls user interface settings for the map.
UIEdgeInsets padding
 Controls the 'visible' region of the view.
GMSMapViewPaddingAdjustmentBehavior paddingAdjustmentBehavior
 Controls how safe area insets are added to the padding values.
BOOL accessibilityElementsHidden
 Defaults to YES.
GMSMapLayerlayer
 Accessor for the custom CALayer type used for the layer.
GMSFrameRate preferredFrameRate
 Controls the rendering frame rate.
GMSCoordinateBoundscameraTargetBounds
 If not nil, constrains the camera target so that gestures cannot cause it to leave the specified bounds.
GMSMapCapabilityFlags mapCapabilities
 All conditionally-available (dependent on mapID or other map settings) capabilities that are available at the current moment in time.

(Note that these are not member functions.)

NSString *const kGMSAccessibilityCompass
 Accessibility identifier for the compass button.
NSString *const kGMSAccessibilityMyLocation
 Accessibility identifier for the "my location" button.
NSString *const kGMSAccessibilityOutOfQuota
 Accessibility identifier for the "out of quota" error label.

Member Function Documentation

- (instancetype) init

Initializes with CGRectZero and default options.

- (instancetype) initWithOptions: (nonnull GMSMapViewOptions *)  options

Creates a new map view with the given options.

The value of the options object is copied by this method.

- (instancetype) initWithFrame: (CGRect)  frame
- (nullable instancetype) initWithCoder: (NSCoder *)  coder
+ (instancetype) mapWithFrame: (CGRect)  frame
camera: (GMSCameraPosition *)  camera 

Builds and returns a map view with a frame and camera target.

+ (instancetype) mapWithFrame: (CGRect)  frame
mapID: (GMSMapID *)  mapID
camera: (GMSCameraPosition *)  camera 

Convenience initializer to build and return a map view with a frame, map ID, and camera target.

- (instancetype) initWithFrame: (CGRect)  frame
camera: (GMSCameraPosition *)  camera 

Builds and returns a map view, with a frame and camera target.

Note:
This is deprecated. Use -init or -initWithOptions: instead.
- (instancetype) initWithFrame: (CGRect)  frame
mapID: (GMSMapID *)  mapID
camera: (GMSCameraPosition *)  camera 

Builds and returns a map view with a frame, map ID, and camera target.

Note:
This is deprecated. Use -init or -initWithOptions: instead.
- (void) startRendering

Tells this map to power up its renderer.

This is optional and idempotent.

Note:
This is deprecated. This method is obsolete and will be removed in a future release.
- (void) stopRendering

Tells this map to power down its renderer.

This is optional and idempotent.

Note:
This is deprecated. This method is obsolete and will be removed in a future release.
- (void) clear

Clears all markup that has been added to the map, including markers, polylines and ground overlays.

This will not clear the visible location dot or reset the current mapType.

- (void) setMinZoom: (float)  minZoom
maxZoom: (float)  maxZoom 

Sets minZoom and maxZoom.

This method expects the minimum to be less than or equal to the maximum, and will throw an exception with name NSRangeException otherwise.

- (nullable GMSCameraPosition *) cameraForBounds: (GMSCoordinateBounds *)  bounds
insets: (UIEdgeInsets)  insets 

Build a GMSCameraPosition that presents bounds with padding.

The camera will have a zero bearing and tilt (i.e., facing north and looking directly at the Earth). This takes the frame and padding of this GMSMapView into account.

If the bounds is invalid this method will return a nil camera.

- (void) moveCamera: (GMSCameraUpdate *)  update

Changes the camera according to update.

The camera change is instantaneous (with no animation).

- (BOOL) areEqualForRenderingPosition: (GMSCameraPosition *)  position
position: (GMSCameraPosition *)  otherPosition 

Check whether the given camera positions would practically cause the camera to be rendered the same, taking into account the level of precision and transformations used internally.

Returns a feature layer of the specified type.

Feature layers must be configured in the Cloud Console.

If a layer of the specified type does not exist on this map, or if data-driven styling is not enabled, or if the Metal rendering framework is not used, the resulting layer's `isAvailable` will be NO, and will not respond to any calls.

Requires the Metal renderer. Learn how to enable Metal at https://developers.google.com/maps/documentation/ios-sdk/config#use-metal

Returns a dataset feature layer of the specified dataset.

Dataset IDs must be configured in the Cloud Console.

If a dataset of the specified ID does not exist on this map, or if data-driven styling is not enabled, the resulting layer's `isAvailable` will be NO, and will not respond to any calls.

- (void) animateToCameraPosition: (GMSCameraPosition *)  cameraPosition

Animates the camera of this map to cameraPosition.

- (void) animateToLocation: (CLLocationCoordinate2D)  location

As animateToCameraPosition:, but changes only the location of the camera (i.e., from the current location to location).

- (void) animateToZoom: (float)  zoom

As animateToCameraPosition:, but changes only the zoom level of the camera.

This value is clamped by [kGMSMinZoomLevel, kGMSMaxZoomLevel].

- (void) animateToBearing: (CLLocationDirection)  bearing

As animateToCameraPosition:, but changes only the bearing of the camera (in degrees).

Zero indicates true north.

- (void) animateToViewingAngle: (double)  viewingAngle

As animateToCameraPosition:, but changes only the viewing angle of the camera (in degrees).

This value will be clamped to a minimum of zero (i.e., facing straight down) and between 30 and 45 degrees towards the horizon, depending on the relative closeness to the earth.

- (void) animateWithCameraUpdate: (GMSCameraUpdate *)  cameraUpdate

Applies cameraUpdate to the current camera, and then uses the result as per animateToCameraPosition:.


- (NSString* const) kGMSAccessibilityCompass [related]

Accessibility identifier for the compass button.

- (NSString* const) kGMSAccessibilityMyLocation [related]

Accessibility identifier for the "my location" button.

- (NSString* const) kGMSAccessibilityOutOfQuota [related]

Accessibility identifier for the "out of quota" error label.


Property Documentation

- (IBOutlet id<GMSMapViewDelegate>) delegate [read, write, assign]

GMSMapView delegate.

- (GMSCameraPosition*) camera [read, write, copy]

Controls the camera, which defines how the map is oriented.

Modification of this property is instantaneous.

- (GMSProjection*) projection [read, assign]

Returns a GMSProjection object that you can use to convert between screen coordinates and latitude/longitude coordinates.

This is a snapshot of the current projection, and will not automatically update when the camera moves. It represents either the projection of the last drawn GMSMapView frame, or; where the camera has been explicitly set or the map just created, the upcoming frame. It will never be nil.

- (BOOL) myLocationEnabled [read, write, assign]

Controls whether the My Location dot and accuracy circle is enabled.

Defaults to NO.

- (CLLocation*) myLocation [read, assign]

If My Location is enabled, reveals where the device location dot is being drawn.

If it is disabled, or it is enabled but no location data is available, this will be nil. This property is observable using KVO.

- (GMSMarker*) selectedMarker [read, write, assign]

The marker that is selected.

Setting this property selects a particular marker, showing an info window on it. If this property is non-nil, setting it to nil deselects the marker, hiding the info window. This property is observable using KVO.

- (BOOL) trafficEnabled [read, write, assign]

Controls whether the map is drawing traffic data, if available.

This is subject to the availability of traffic data. Defaults to NO.

- (GMSMapViewType) mapType [read, write, assign]

Controls the type of map tiles that should be displayed.

Defaults to kGMSTypeNormal.

- (GMSMapStyle*) mapStyle [read, write, assign]

Controls the style of the map.

A non-nil mapStyle will only apply if mapType is Normal.

- (UIUserInterfaceStyle) overrideUserInterfaceStyle [read, write, assign]

Change the map to desired [UIUserInterfaceStyle](https://developer.apple.com/documentation/uikit/uiuserinterfacestyle?language=objc).

This overrides the default UIKit behavior and defaults to UIUserInterfaceStyleLight to ensure backwards compatibility. This affects the color scheme of Normal and Terrain map types.

- (float) minZoom [read, assign]

Minimum zoom (the farthest the camera may be zoomed out).

Defaults to kGMSMinZoomLevel. Modified with -setMinZoom:maxZoom:.

- (float) maxZoom [read, assign]

Maximum zoom (the closest the camera may be to the Earth).

Defaults to kGMSMaxZoomLevel. Modified with -setMinZoom:maxZoom:.

- (BOOL) buildingsEnabled [read, write, assign]

If set, 3D buildings will be shown where available.

Defaults to YES.

This may be useful when adding a custom tile layer to the map, in order to make it clearer at high zoom levels. Changing this value will cause all tiles to be briefly invalidated.

- (BOOL) indoorEnabled [read, write, assign]

Sets whether indoor maps are shown, where available.

Defaults to YES.

If this is set to NO, caches for indoor data may be purged and any floor currently selected by the end-user may be reset.

- (GMSIndoorDisplay*) indoorDisplay [read, assign]

Gets the GMSIndoorDisplay instance which allows to observe or control aspects of indoor data display.

- (GMSUISettings*) settings [read, assign]

Gets the GMSUISettings object, which controls user interface settings for the map.

- (UIEdgeInsets) padding [read, write, assign]

Controls the 'visible' region of the view.

By applying padding an area around the edge of the view can be created which will contain map data but will not contain UI controls.

If the padding is not balanced, the visual center of the view will move as appropriate. Padding will also affect the projection property so the visible region will not include the padding area. GMSCameraUpdate fitToBounds will ensure that both this padding and any padding requested will be taken into account.

This property may be animated within a UIView-based animation block.

Controls how safe area insets are added to the padding values.

Like padding, safe area insets position map controls such as the compass, my location button and floor picker within the device safe area.

Defaults to kGMSMapViewPaddingAdjustmentBehaviorAlways.

- (BOOL) accessibilityElementsHidden [read, write, assign]

Defaults to YES.

If set to NO, GMSMapView will generate accessibility elements for overlay objects, such as GMSMarker and GMSPolyline.

This property follows the informal UIAccessibility protocol, except for the default value of YES.

- (GMSMapLayer*) layer [read, retain]

Accessor for the custom CALayer type used for the layer.

- (GMSFrameRate) preferredFrameRate [read, write, assign]

Controls the rendering frame rate.

Default value is kGMSFrameRateMaximum.

- (GMSCoordinateBounds*) cameraTargetBounds [read, write, assign]

If not nil, constrains the camera target so that gestures cannot cause it to leave the specified bounds.

All conditionally-available (dependent on mapID or other map settings) capabilities that are available at the current moment in time.

Does not include always-available capabilities.