Class Maps

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

Maps

Allows for direction finding, geocoding, elevation sampling and the creation of static map images.

Properties

Property Type Description
Direction Finder
Direction Finder Enums
Static Map
Static Map Enums

Methods

Method Return type Brief description
Number[] Decodes an encoded polyline string back into an array of points.
String Encodes an array of points into a string.
Direction Finder Creates a new DirectionFinder object.
Elevation Sampler Creates an ElevationSampler object.
Geocoder Creates a new Geocoder object.
Static Map Creates a new StaticMap object.
void Resets the authentication credentials to use the default quota allowances.
void Enables the use of an API key to authenticate requests to leverage additional quotas.
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()

Creates a new DirectionFinder object.

Return

DirectionFinder — A new direction finder object.


newElevationSampler()

Creates an ElevationSampler object.

Return

ElevationSampler — A new elevation sampler object.


newGeocoder()

Creates a new Geocoder object.

Return

Geocoder — A new geocoder object.


newStaticMap()

Creates a new StaticMap object.

Return

StaticMap — A new static map object.


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 setAuthentication(clientId, signingKey) is being used for authentication.


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 setAuthenticationByApiKey(apiKey, signingKey) method instead.

 Maps 
 . 
 setAuthenticationByApiKey 
 ( 
 'BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0' 
 ); 

Parameters

Name Type Description
api Key
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 apiKey is null , or if setAuthentication(clientId, signingKey) is already being used for authentication


setAuthenticationByApiKey(apiKey, signingKey)

Enables the use of an API key and Signing Key to authenticate requests to leverage additional quotas in StaticMap. While the signingKey is required for requests to the Static Map API, this method can also be used to authenticate other Maps services. In those cases, the signingKey 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 Key
String An API key which can be obtained from the Google Cloud Console by following steps mentioned in the quickstart guide .
signing Key
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 apiKey is null , or if setAuthentication(clientId, signingKey) is already being used for authentication

See also

Deprecated methods

Create a Mobile Website
View Site in Mobile | Classic
Share by: