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 via the convenience constructor [GMSMapView mapWithFrame:camera:]. It may also be created with the default [[GMSMapView alloc] initWithFrame:] method (wherein its camera will be set to a default location).
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) | - 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. | |
(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:. | |
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< GMSMapViewDelegate > | delegate |
GMSMapView delegate. | |
GMSCameraPosition * | camera |
Controls the camera, which defines how the map is oriented. | |
GMSProjection * | projection |
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 user location dot is being drawn. | |
GMSMarker * | selectedMarker |
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. | |
GMSMapStyle * | mapStyle |
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. | |
GMSIndoorDisplay * | indoorDisplay |
Gets the GMSIndoorDisplay instance which allows to observe or control aspects of indoor data display. | |
GMSUISettings * | settings |
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. | |
GMSMapLayer * | layer |
Accessor for the custom CALayer type used for the layer. | |
GMSFrameRate | preferredFrameRate |
Controls the rendering frame rate. | |
GMSCoordinateBounds * | cameraTargetBounds |
If not nil, constrains the camera target so that gestures cannot cause it to leave the specified bounds. | |
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. | |
GMSNavigator * | navigator |
The navigator for this GMSMapView which allows routes to be requested and turn-by-turn guidance to be started. | |
GMSRoadSnappedLocationProvider * | roadSnappedLocationProvider |
Allows subscription to road-snapped location updates. | |
GMSLocationSimulator * | locationSimulator |
Allows the user location to be simulated. | |
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 user's location. | |
GMSNavigationTravelMode | travelMode |
The travel mode which determines what type of routes will be fetched and the way that user 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. | |
Related Functions | |
(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. |
Member Function Documentation
+ (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.
- (instancetype) initWithFrame: | (CGRect) | frame | |
mapID: | (GMSMapID *) | mapID | |
camera: | (GMSCameraPosition *) | 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.
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.
- (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:.
Friends And Related Function Documentation
- (NSString* const) kGMSAccessibilityCompass [related] |
Accessibility identifier for the compass button.
- (NSString* const) kGMSAccessibilityMyLocation [related] |
Accessibility identifier for the "my location" button.
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 user 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.
- (GMSMapViewPaddingAdjustmentBehavior) paddingAdjustmentBehavior [read, write, assign] |
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 is as per 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.
- (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 user 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.
- (GMSRoadSnappedLocationProvider*) roadSnappedLocationProvider [read, assign] |
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.
- (GMSLocationSimulator*) locationSimulator [read, assign] |
Allows the user location to be simulated.
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.
- (GMSNavigationCameraPerspective) followingPerspective [read, write, assign] |
The camera perspective that will be used when following the user'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 user course is determined.
In driving mode user course is based on the direction of movement, whilst in cycling or walking mode it is based on the compass direction the device is facing. User course is represented by the direction of the user 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.
- (GMSNavigationRouteCalloutFormat) routeCalloutFormat [read, write, assign] |
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 user location (i.e. cameraMode
equals GMSNavigationCameraModeFollowing
). This can be set to GMSNavigationNoFollowingZoomLevel
if no zoom level override should be used.