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.
(void) - invalidateLayoutForAccessoryView:
 Invalidates an accessory view and triggers a re-layout for that view.
(void) - setHeaderAccessoryView:
 Sets the position of the accessory view below the primary header of the navigation UI.
(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:.
(BOOL) - enableNavigationWithSession:
 Begins navigation in this map view using the given navigation session.

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.
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.
IBOutlet id
< GMSMapViewNavigationUIDelegate
navigationUIDelegate
 A delegate of GMSMapView which receives callbacks for navigation UI events.
BOOL navigationEnabled
 Whether navigation functionality is enabled for this map.
GMSNavigatornavigator
 The navigator for this GMSMapView which allows routes to be requested and turn-by-turn guidance to be started.
GMSRoadSnappedLocationProviderroadSnappedLocationProvider
 Allows subscription to road-snapped location updates.
GMSLocationSimulatorlocationSimulator
 Allows you to simulate the device location.
GMSNavigationCameraMode cameraMode
 The mode of the camera which determines its behavior when the navigationEnabled property is set to YES.
GMSNavigationCameraPerspective followingPerspective
 The camera perspective that will be used when following the device's location.
GMSNavigationTravelMode travelMode
 The travel mode which determines what type of routes will be fetched and the way that device course is determined.
GMSNavigationLightingMode lightingMode
 The lighting mode determines which color scheme should be used for rendering the map.
BOOL shouldDisplaySpeedLimit
 Determines whether the speed limit should be displayed when guidance is active and speed limit data is available.
BOOL shouldDisplaySpeedometer
 Specifies whether the speedometer icon is shown.
UILayoutGuide * navigationHeaderLayoutGuide
 The rectangle that is covered by the navigation header.
UILayoutGuide * navigationFooterLayoutGuide
 The rectangle that is covered by the navigation footer.
GMSNavigationRouteCalloutFormat routeCalloutFormat
 Specifies which route callout format (default, time, or distance) to use.
float followingZoomLevel
 Customized zoom level during navigation.
GMSRoadSnappedLocationProviderroadSnappedMyLocationSource
 Sets the My Location provider for this map view.

(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.

- (GMSFeatureLayer<GMSPlaceFeature *> *) featureLayerOfFeatureType: (GMSFeatureType)  featureType

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

- (void) invalidateLayoutForAccessoryView: (UIView< GMSNavigationAccessoryView > *)  accessoryView

Invalidates an accessory view and triggers a re-layout for that view.

The view must be one of the current accessory views. If guidance is inactive, this call is a NO-OP instruction.

- (void) setHeaderAccessoryView: (nullable UIView< GMSNavigationAccessoryView > *)  headerAccessoryView

Sets the position of the accessory view below the primary header of the navigation UI.

Passing a nil value removes the accessory view. If guidance is inactive, this call is a NO-OP instruction.

@note If the map view is short, the SDK hides the accessory view due to limited space. The views are internally managed to optimize display of the map.

- (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:.

- (BOOL) enableNavigationWithSession: (GMSNavigationSession *)  navigationSession

Begins navigation in this map view using the given navigation session.

Returns:
Whether navigation was successfully started (for instance, NO will be returned if the terms and conditions have not yet been accepted).

- (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.

- (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.

- (IBOutlet id<GMSMapViewNavigationUIDelegate>) navigationUIDelegate [read, write, assign]

A delegate of GMSMapView which receives callbacks for navigation UI events.

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

Whether navigation functionality is enabled for this map.

If this is YES, routes and turn-by-turn directions can be displayed on the map, the camera can enter following mode, and the re-center button appears when the camera is not following the device location.

If the user has not accepted the Google Navigation terms and conditions, setting this property will have no effect. To show the terms and conditions dialog, see the methods on GMSNavigationServices.

- (GMSNavigator*) navigator [read, assign]

The navigator for this GMSMapView which allows routes to be requested and turn-by-turn guidance to be started.

If the user has not accepted the Google Navigation terms and conditions, this will be nil. To show the terms and conditions dialog, see the methods on GMSNavigationServices.

Allows subscription to road-snapped location updates.

If the user has not accepted the Google Navigation terms and conditions, this will be nil. To show the terms and conditions dialog, see the methods on GMSNavigationServices.

Allows you to simulate the device location.

The simulated location affects the position of the chevron on the map, the progress of turn-by-turn guidance, and the updates provided by the road-snapped location provider.

If the user has not accepted the Google Navigation terms and conditions, this will be nil. To show the terms and conditions dialog, see the methods on GMSNavigationServices.

- (GMSNavigationCameraMode) cameraMode [read, write, assign]

The mode of the camera which determines its behavior when the navigationEnabled property is set to YES.

See GMSNavigationCameraMode for the available modes.

The camera perspective that will be used when following the device's location.

The navigationEnabled property must be set to YES and cameraMode must be set to GMSNavigationCameraModeFollowing for this perspective to take effect.

- (GMSNavigationTravelMode) travelMode [read, write, assign]

The travel mode which determines what type of routes will be fetched and the way that device course is determined.

In driving mode, device course is based on the direction of movement, while in cycling or walking mode the course is based on the compass direction the device is facing. Device course is represented by the direction of the device location marker and reported by the GMSRoadSnappedLocationProvider.

- (GMSNavigationLightingMode) lightingMode [read, write, assign]

The lighting mode determines which color scheme should be used for rendering the map.

It is also used to determine the default colors of various interface elements.

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

Determines whether the speed limit should be displayed when guidance is active and speed limit data is available.

The default value is NO.

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

Specifies whether the speedometer icon is shown.

When enabled, a speedometer icon that indicates the vehicle speed appears in the bottom corner during guidance. When reliable speed limit data is available, the speed limit icon is also visible, and is attached with the speedometer icon. The speedometer icon can have different colors for text and background, depending on the speed alert severity.

If the recenter button is enabled, then the speed limit and the speedometer icon are temporarily hidden when the recenter button displays.

- (UILayoutGuide*) navigationHeaderLayoutGuide [read, assign]

The rectangle that is covered by the navigation header.

Height is zero when the header is hidden.

- (UILayoutGuide*) navigationFooterLayoutGuide [read, assign]

The rectangle that is covered by the navigation footer.

Height is zero when the footer is hidden.

Specifies which route callout format (default, time, or distance) to use.

- (float) followingZoomLevel [read, write, assign]

Customized zoom level during navigation.

Setting this value will override the default Navigation SDK zoom level when the camera is following device location (i.e. cameraMode equals GMSNavigationCameraModeFollowing). This can be set to GMSNavigationNoFollowingZoomLevel if no zoom level override should be used.

Sets the My Location provider for this map view.

Normally the My Location dot and accuracy circle for a map view are driven by the actual device location. By setting this property, the My Location dot and accuracy circle will be driven by the road-snapped location from the given location provider instead. To return to the normal behavior, set this property to nil.

This has no effect when navigationEnabled is on for this map view.