This overview describes how to configure a map that was added to an iOS app using the Maps SDK for iOS.
After you add a map to your app, you can configure initial options and runtime settings of the map. For details about adding a map container, see the Add a map.
The initial map settings include the following:
- The camera position, including: location, zoom, bearing and tilt. See Camera and View for details on camera positioning.
- The map background color.
- The map type.
- The UI components to display, such as the zoom buttons and compass.
- The gestures to enable.
At runtime you can configure these settings and some addition settings by
When initializing your map view, configuration options are set with
GMSMapViewOptions. Option properties include the
The map frame. Defaults to CGRectZero.
The default map camera position.
Google mapID. Optional parameter.
Defaults to UIColor.lightGray
Required for CarPlay. Implies a default value for the main screen.
Configure map options
You can either set your own option properties, or pass an instantiated
GMSMapViewOptions with default values directly to
let options = GMSMapViewOptions() options.camera = GMSCameraPosition.camera(withLatitude: -33.8683, longitude: 151.2086, zoom: 6) let mapView = GMSMapView(options:options)
GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; options.camera = [GMSCameraPosition cameraWithLatitude:-33.8683 longitude:151.2086 zoom:6]; GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options];
Here's an example of passing a
GMSMapViewOptions object with default values
let options = GMSMapViewOptions() let mapView = GMSMapView(options:options) //initialized with default values
GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options]; //initialized with default values
Configure background color
When working in dark mode or switching between map views, it may be useful to
override the default map background color. This can be achieved by setting the
let options = GMSMapViewOptions() options.backgroundColor = UIColor.yellowColor let mapView = GMSMapView(options:options)
GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; options.backgroundColor = UIColor.yellowColor; GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options];
You can customize your map with one of several map types. A map's type governs the overall representation of the map. For example, an atlas usually contains political maps that focus on showing boundaries, and road maps that show all of the roads for a city or region. The Maps SDK for iOS offers the following types of maps:
Typical road map. Shows roads, some features built by humans, and important natural features like rivers. Road and feature labels are also visible.
Satellite photograph data with road maps added. Road and feature labels are also visible.
Satellite photograph data. Road and feature labels are not visible.
Topographic data. The map includes colors, contour lines and labels, and perspective shading. Some roads and labels are also visible.
No map tiles. The base map tiles will not be rendered. This mode is useful in conjunction with tile layers. The display of traffic data is disabled when the map type is set to none.
Changing the map type
To set the type of a map, assign a new value to the
property. For example, to display a satellite map type:
let options = GMSMapViewOptions() options.camera = GMSCameraPosition.camera(withLatitude: -33.8683, longitude: 151.2086, zoom: 6) let mapView = GMSMapView(options:options) mapView.mapType = .satellite
GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; options.camera = [GMSCameraPosition cameraWithLatitude:-33.8683 longitude:151.2086 zoom:6]; GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options]; mapView.mapType = kGMSTypeSatellite;
The chooser below shows a comparison of terrain, normal and hybrid maps for the same location:
At high zoom levels, the Maps SDK for iOS will show floor plans for
indoor spaces such as airports, shopping malls, large retail stores, and transit
stations. Indoor floor plans are integrated into the default map tiles for the
'normal' map type (
kGMSTypeNormal), and are automatically enabled when the
user zooms in, and fade away when the map is zoomed out.
You can disable indoor maps by setting the
indoorEnabled property of
mapView.isIndoorEnabled = false
mapView.indoorEnabled = NO;
Alternatively, you can disable just the Floor Picker control.
Adding floor plans
Floor plans are available in select locations. If floor plan data is not available for a building that you would like to highlight in your application, you can:
- Add floor plans to Google Maps directly. This makes your plans are available to all users of Google Maps.
- Display a floor plan as a Ground Overlay. This enables only users of your application to view your floor plans.
The traffic layer
You can give your users the ability to view the map with traffic density
information superimposed on top of it. This provides a visual summary of their
local traffic situation. You can turn the traffic layer on and off by calling
method. The following example shows how the traffic layer might appear on a map.
By default, accessibility elements on the map are hidden. You may enable
accessibility by setting the
accessibilityElementsHidden property of
NO. This causes accessibility elements to be generated for
overlay objects (such as
GMSMarker and info windows,
mapView.accessibilityElementsHidden = false
mapView.accessibilityElementsHidden = NO;
This property is as per the informal
UIAccessibility protocol, except that the
default value in the Maps SDK for iOS is
By default, no location data is shown on the map. You may enable the blue "My
Location" dot and compass direction by setting
mapView.isMyLocationEnabled = true
mapView.myLocationEnabled = YES;
Enabling this feature provides the user's current location through the
myLocation property. This property may not be immediately available - for
example, if the user is prompted by iOS to allow access to this data. It is
nil in this case.
print("User's location: \(String(describing: mapView.myLocation))")
NSLog(@"User's location: %@", mapView.myLocation);
Many cities, when viewed close up, will have 3D buildings visible, as viewable in the image of Seattle, Washington below.
You can disable the 3D buildings by setting the corresponding
property in Swift or Objective-C, as shown below:
mapView.isBuildingsEnabled = false
A Google Map is designed to fill the entire region defined by the
Several aspects of how the map appears and behaves are defined by the dimensions
of the view:
- The camera's target reflects the center of the padded region.
- Map controls are positioned relative to the edges of the map.
- Legal information, such as copyright statements or the Google logo appear along the bottom edge of the map.
You can add padding around the edges of the map using the
padding property. The map continues to fill
the entire container, but text and control positioning, map gestures, and camera
movements behave as if it has been placed in a smaller space. This results in
the following changes:
- Camera movements using API calls or button presses (e.g., compass, my location) are relative to the padded region.
projectionreturns a projection that includes only the padded region.
- UI controls are offset from the edge of the container by the specified number of points.
Padding can be helpful when designing UIs that overlap some portion of the map. For example, in the image, the map is padded along the top and right edges. Visible map controls and legal text is displayed along the edges of the padded region, shown in green, while the map continues to fill the entire container, shown in blue. In this example, you could float a menu over the right side of the map without obscuring map controls.
To add padding to your map, create a
UIEdgeInsets object and pass it to the
// Insets are specified in this order: top, left, bottom, right let mapInsets = UIEdgeInsets(top: 100.0, left: 0.0, bottom: 0.0, right: 300.0) mapView.padding = mapInsets
// Insets are specified in this order: top, left, bottom, right UIEdgeInsets mapInsets = UIEdgeInsetsMake(100.0, 0.0, 0.0, 300.0); mapView.padding = mapInsets;