Google.Maps.MapsService

The MapsService class serves as the entry point for interacting with the Maps Unity SDK.

Summary

The SDK instantiates this class as a Unity script component called Maps Service (Script). You use it in a Unity scene by adding the Maps Service (Script) component to an empty GameObject in your scene. This GameObject becomes your anchor—and the map feature GameObjects that the SDK generates are added as its children.

You can configure options using the Inspector, but you cannot change most options after calling Awake (for example, you cannot change the ZoomLevel). However, you can create multiple MapsService instances, each with different properties. For example, you could add a bird's-eye mini-map with a different zoom level to your main map.

Inheritance

Inherits from: MonoBehaviour

Public attributes

AdsImpressionsApiAddress = "geoads.googleapis.com"
string
Ads impressions API address.
ApiKey
string
The API key. You must have both the Vector Tile API and the Playable Locations API enabled. For more information, see Get API Key.
CountryProvider
Country code provider.
CreateAdEventManager = true
bool
Indicates whether an AdEventManager will be added to this MapsService on Awake.
EnableDiagnostics = true
bool
Specifies whether to send diagnostic information to Google. An example of diagnostic information is frame rate.
EnableModeledStructures = true
bool
Specifies whether to enable Feature.ModeledStructure features.
EnablePoliticalFeatures = false
bool
Specifies whether to enable political features such as administrative areas.
NetworkPoolSize = 100
int
Maximum number of concurrent connections to the Vector Tile API.
NetworkTimeoutSeconds = 10
int
The maximum length of time (in seconds) to wait for a response after requesting map data.
ObjectCreationFrameBudget = 0
long
The maximum length of time (in milliseconds) per frame, to use for creating GameObjects.
StaticBatching = false
bool
Specifies whether to enable static batching for all generated GameObjects.
VectorTileApiAddress = "vectortile.googleapis.com"
string
The domain address of the Vector Tile API.
ZoomLevel = 17
int
The map zoom (magnification) level.

Properties

AdEventManager
Reports Ad events to the server.
CacheOptions
A container of parameters used for caching map data.
Coords
The game world coordinate system.
Events
A container for all of the events fired by the SDK.
GameObjectManager
Tracks destroyed and suppressed GameObjects.

Public static functions

EnableVerboseLogging(bool enable)
void
Specifies whether to enable verbose logging.

Public functions

CreateRoadLatticeDebugObject()
GameObject
Creates a GameObject representing the current state of the global MapsService.RoadLattice.
InitFloatingOrigin(LatLng floatingOrigin)
void
Sets the initial origin of the coordinate system.
LoadMap(Bounds bounds, GameObjectOptions options)
void
Loads a rectangular region (bounds) of the map.
MakeMapLoadRegion()
Initializes a MapLoadRegion object to load a region of the map.
MoveFloatingOrigin(LatLng floatingOrigin, ICollection< GameObject > gameObjects)
Vector3
Re-establishes the origin based on a new Coord.LatLng value.
MoveFloatingOrigin(Vector3 floatingOrigin, ICollection< GameObject > gameObjects)
Vector3
Reestablishes the origin based based on a new Vector3 value.

Public attributes

AdsImpressionsApiAddress

string AdsImpressionsApiAddress = "geoads.googleapis.com"

Ads impressions API address.

Modifying this field has no effect after Awake is called.

ApiKey

string ApiKey

The API key. You must have both the Vector Tile API and the Playable Locations API enabled. For more information, see Get API Key.

Note: If you modify this field after calling Awake, it has no effect.

CountryProvider

CountryProvider CountryProvider

Country code provider.

CreateAdEventManager

bool CreateAdEventManager = true

Indicates whether an AdEventManager will be added to this MapsService on Awake.

EnableDiagnostics

bool EnableDiagnostics = true

Specifies whether to send diagnostic information to Google. An example of diagnostic information is frame rate.

Caution: You must set this value before the Unity runtime calls Awake.

EnableModeledStructures

bool EnableModeledStructures = true

Specifies whether to enable Feature.ModeledStructure features.

When set to false, Feature.ExtrudedStructure features are used instead, which results in reduced network traffic, CPU usage, and memory usage.

If you modify this field after Awake is called, then your change won't take effect.

EnablePoliticalFeatures

bool EnablePoliticalFeatures = false

Specifies whether to enable political features such as administrative areas.

When set to true, political features such as administrative areas and localities are created.

Currently, the only political features that are returned are Japanese prefectures and wards.

NetworkPoolSize

int NetworkPoolSize = 100

Maximum number of concurrent connections to the Vector Tile API.

If you use a value less than 100, then you should expect longer load times for map data.

Warning: This field is experimental. Its value might change in a future release.

NetworkTimeoutSeconds

int NetworkTimeoutSeconds = 10

The maximum length of time (in seconds) to wait for a response after requesting map data.

When you set this value to 0, there is no limit to the wait time.

Note: This attribute is an integer rather than a floating point due to a limitation of the UnityWebRequest object.

ObjectCreationFrameBudget

long ObjectCreationFrameBudget = 0

The maximum length of time (in milliseconds) per frame, to use for creating GameObjects.

Setting this to 0 gives you an unlimited length of time, but practically speaking, the length of time is limited by how quickly areas can be loaded.

If you modify this field after Awake is called, then your change won't take effect.

StaticBatching

bool StaticBatching = false

Specifies whether to enable static batching for all generated GameObjects.

When enabled, GameObjects are statically batched, unless otherwise specified in the corresponding WillCreate event.

If you modify this field after calling Awake, then your change won't take effect.

VectorTileApiAddress

string VectorTileApiAddress = "vectortile.googleapis.com"

The domain address of the Vector Tile API.

If you modify this field after calling Awake, then your change won't take effect.

ZoomLevel

int ZoomLevel = 17

The map zoom (magnification) level.

Controls the level of detail of map data (the set of feature types returned, their density, and geometry simplification). This determines the size of the requested map tiles.

The default zoom level is 17—which is considered appropriate for location-based games because lower zoom levels can miss important features such as buildings. Zoom level 17 is also considered more stable, meaning the set of features returned is less likely to change.

If you modify this field after Awake is called, then your change won't take effect.

Properties

AdEventManager

AdEventManager AdEventManager

Reports Ad events to the server.

CacheOptions

CacheOptions CacheOptions

A container of parameters used for caching map data.

If you modify this field after Awake is called, then your change won't take effect.

Coords

Coords Coords

The game world coordinate system.

Manages the floating-point origin, Mercator scale, and converts between Unity Worldspace (Vector3), Earth-scale Mercator Space (Vector2D), and Google Maps Tile Coordinates (Coord.TileCoord). Note: You must set the floating point origin before using the coordinate system.

See also: InitFloatingOrigin

Details
Exceptions
FloatingOriginNotSetException
Thrown when you use the coordinate system before setting the floating-point origin.

Events

Events Events

A container for all of the events fired by the SDK.

Events are part of the mechanism that allows you to style map feature GameObjects. For example, the SDK fires WillCreate and DidCreate events when it generates Feature.MapFeature objects and their corresponding GameObject during map loading. These events contain geometry information and metadata that you can use to style the GameObject.

GameObjectManager

GameObjectManager GameObjectManager

Tracks destroyed and suppressed GameObjects.

It notifies the SDK whenever a GameObject is destroyed so that it can then be recreated properly on subsequent calls to MapsService.LoadMap.

Public static functions

EnableVerboseLogging

void EnableVerboseLogging(
  bool enable
)

Specifies whether to enable verbose logging.

Enables/disables logging verbose debug information to the Unity console. Note: This feature is available only in debug builds.

Details
Parameters
enable
Specifies whether to enable or disable verbose logging.

Public functions

CreateRoadLatticeDebugObject

GameObject CreateRoadLatticeDebugObject()

Creates a GameObject representing the current state of the global MapsService.RoadLattice.

Details
Returns
A GameObject with multiple children each of which has an attached Mesh representing part of the current RoadLattice.

InitFloatingOrigin

void InitFloatingOrigin(
  LatLng floatingOrigin
)

Sets the initial origin of the coordinate system.

When converting Coord.LatLng values to and from Unity Worldspace, Vector3 values are translated relative to the current origin.

The initial origin value is used to determine the Unity Worldspace scale for the entire gaming session. Mercator scale is based on the latitude, per the Web Mercator projection.

The recommended floatingOrigin value to use is the player's starting location. It should be near the player's current location to ensure that Unity Worldspace Vector3 values remain small to avoid single precision floating point errors.

Details
Parameters
floatingOrigin
The initial origin value.
Exceptions
System.InvalidOperationException
Thrown when the origin has already been set.

LoadMap

void LoadMap(
  Bounds bounds,
  GameObjectOptions options
)

Loads a rectangular region (bounds) of the map.

GameObjects are asynchronously created for all map features within the bounds that you specify. Note: You must set the origin to Coord.Coords before calling this method.

Calling this function is equivalent to calling LoadMapRegion().Bounds(bounds).Load(options).

See also: InitFloatingOrigin

Details
Parameters
bounds
Defines a rectangular region.
options
User defined options which customise map construction.
Exceptions
FloatingOriginNotSetException
Thrown when the floating-point origin isn't set.

MakeMapLoadRegion

MapLoadRegion MakeMapLoadRegion()

Initializes a MapLoadRegion object to load a region of the map.

GameObjects are asynchronously created for all map features within the bounds that you specify. You must set the floating-point origin to Coord.Coords before calling this method.

The following example loads the region of the map visible in the main camera's viewport.

MapsService.MakeMapLoadRegion().AddViewport(Camera.main).Load(options);
  

MoveFloatingOrigin

Vector3 MoveFloatingOrigin(
  LatLng floatingOrigin,
  ICollection< GameObject > gameObjects
)

Re-establishes the origin based on a new Coord.LatLng value.

You should re-establish the origin whenever the user moves far enough away from the origin that floating-point errors become noticeable.

This method translates all map feature GameObjects created by the SDK. You can pass in additional GameObjects to be translated. You can also use the returned Vector3 offset value to manually translate additional GameObjects yourself.

This method is an overload of the method MoveFloatingOrigin(Vector3, ICollection<GameObject>).

See Also:InitFloatingOrigin(LatLng).

The following code snippet re-establishes the origin to London. Two camera objects are also moved, to keep all GameObjects in the same position relative to the camera.

MapsService.MoveFloatingOrigin(
        new LatLng(51.5081, -0.0760),
        new GameObject[] {camera1, camera2});
  

Details
Parameters
floatingOrigin
The new origin value.
gameObjects
Additional GameObjects to be translated (if there are any).
Exceptions
FloatingOriginNotSetException
Thrown when the origin has not been set.
Returns
A Vector3 offset that you can use for manually translating GameObjects to reposition them relative to the new origin.

MoveFloatingOrigin

Vector3 MoveFloatingOrigin(
  Vector3 floatingOrigin,
  ICollection< GameObject > gameObjects
)

Reestablishes the origin based based on a new Vector3 value.

This method is an overload of the method MoveFloatingOrigin(LatLng, ICollection<GameObject>).

See also: InitFloatingOrigin(LatLng)

Details
Parameters
floatingOrigin
The new origin as a Vector3 value.
gameObjects
Additional GameObjects to be moved (if there are any).
Exceptions
FloatingOriginNotSetException
Thrown when the floating-point origin has not been set.
Returns
A Vector3 offset value, for manually moving GameObjects.

Send feedback about...

Google Maps Platform gaming solution
Google Maps Platform gaming solution