Page Summary
-
The Maps service allows for finding directions, geocoding, sampling elevation, and creating static map images.
-
It includes properties for DirectionFinder and StaticMap enums.
-
Key methods include decoding and encoding polylines, creating new instances of DirectionFinder, ElevationSampler, Geocoder, and StaticMap, and setting authentication for Google Maps APIs Premium Plan accounts.
Allows for direction finding, geocoding, elevation sampling and the creation of static map images.
Properties
| Property | Type | Description |
|---|---|---|
Direction | Direction | |
Static | Static |
Methods
| Method | Return type | Brief description |
|---|---|---|
decode | Number[] | Decodes an encoded polyline string back into an array of points. |
encode | String | Encodes an array of points into a string. |
new | Direction | Creates a new DirectionFinder object. |
new | Elevation | Creates an ElevationSampler object. |
new | Geocoder | Creates a new Geocoder object. |
new | Static | Creates a new StaticMap object. |
reset | void | Resets the authentication credentials to use the default quota allowances. |
set | void | Enables the use of an API key to authenticate requests to leverage additional quotas. |
set | void | Enables the use of an API key and Signing Key to authenticate requests to leverage additional quotas in StaticMap. |
Detailed documentation
decodePolyline(polyline)
Decodes an encoded polyline string back into an array of points.
// Decodes a string representation of the latitudes and longitudes of // Minneapolis and Milwaukee respectively. const polyline = 'qvkpG`qhxPbgyI_zq_@'; const points = Maps.decodePolyline(polyline); for (let i = 0; i < points.length; i += 2) { Logger.log('%s, %s', points[i], points[i + 1]); }
Parameters
| Name | Type | Description |
|---|---|---|
polyline | String | An encoded polyline to decode. |
Return
Number[] — An array of latitude longitude pairs (lat0, long0, lat1, long1, ...).
See also
encodePolyline(points)
Encodes an array of points into a string.
// The latitudes and longitudes of New York and Boston respectively. const points = [40.77, -73.97, 42.34, -71.04]; const polyline = Maps.encodePolyline(points);
Parameters
| Name | Type | Description |
|---|---|---|
points | Number[] | An array of latitude/longitude pairs to encode. |
Return
String — An encoded string representing those points.
See also
newDirectionFinder()
newElevationSampler()
newGeocoder()
newStaticMap()
resetAuthenticationApiKey()
Resets the authentication credentials to use the default quota allowances. This method works
when you are using API key to authenticate requests. This method can be used to revert back to
the default quota allowances if you want to use the Maps methods without providing
authentication credentials.
Maps.resetAuthenticationApiKey();
Throws
Error — if is being used for authentication.set
setAuthenticationByApiKey(apiKey)
Enables the use of an API key to authenticate requests to leverage additional quotas.
This method is used to set an API key which is used to authenticate requests. When this
method is called, quota consumption and billing are charged to the Google Cloud project
associated with the provided API key according to the pricing sheet. You are able
to use the Maps methods with the default quota allowances without providing
authentication credentials. If you are using StaticMap, please use set method instead.
Maps.setAuthenticationByApiKey('BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0');
Parameters
| Name | Type | Description |
|---|---|---|
api | String | An API key which can be obtained from the Google Cloud Console by following steps mentioned in the quickstart guide. |
Throws
Error — if the api is null, or if is already being used for authenticationset
setAuthenticationByApiKey(apiKey, signingKey)
Enables the use of an API key and Signing Key to authenticate requests to leverage additional
quotas in StaticMap. While the signing is required for requests to the Static Map
API, this method can also be used to authenticate other Maps services. In those cases, the
signing parameter is ignored.
This method is used to set an API key and Signing Key which is used to authenticate requests. Signing Key is required for StaticMap, it accepts a small number of requests without signature for testing purposes, but they start failing once it hits the threshold in your production. More details can be found here.
Maps.setAuthenticationByApiKey('BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0', '7_pry-Skg0PKxds-7nvdl91mB5=');
Parameters
| Name | Type | Description |
|---|---|---|
api | String | An API key which can be obtained from the Google Cloud Console by following steps mentioned in the quickstart guide. |
signing | String | A signing key which can be obtained from the Google Cloud Console by following steps mentioned in the guide for digital signature. This is required for StaticMap and ignored for other Maps services. |
Throws
Error — if the api is null, or if is already being used for authenticationset