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

Properties

PropertyTypeDescription
DirectionFinderDirectionFinderEnums
StaticMapStaticMapEnums

Methods

MethodReturn typeBrief description
decodePolyline(polyline)Number[]Decodes an encoded polyline string back into an array of points.
encodePolyline(points)StringEncodes an array of points into a string.
newDirectionFinder()DirectionFinderCreates a new DirectionFinder object.
newElevationSampler()ElevationSamplerCreates an ElevationSampler object.
newGeocoder()GeocoderCreates a new Geocoder object.
newStaticMap()StaticMapCreates a new StaticMap object.
setAuthentication(clientId, signingKey)voidEnables the use of an externally establishedGoogle Maps APIs Premium Plan account,to leverage additionalquotaallowances.

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.constpolyline='qvkpG`qhxPbgyI_zq_@';constpoints=Maps.decodePolyline(polyline);for(leti=0;i <points.length;i+=2){Logger.log('%s, %s',points[i],points[i+1]);}

Parameters

NameTypeDescription
polylineStringAn 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.constpoints=[40.77,-73.97,42.34,-71.04];constpolyline=Maps.encodePolyline(points);

Parameters

NameTypeDescription
pointsNumber[]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.


setAuthentication(clientId, signingKey)

Enables the use of an externally establishedGoogle Maps APIs Premium Plan account,to leverage additionalquotaallowances. Your client ID and signing key can be obtained from the Google EnterpriseSupport Portal. Set these values tonull to go back to using the default quotaallowances.

Note: This method doesn't work with API keys. Additionally,please note that Premium Plan is no longer available for new customers. If you don't alreadyhave a Premium Plan license, please don't callsetAuthentication(clientId, signingKey). You are able to usetheMaps methods with the default quota allowances.

Maps.setAuthentication('gme-123456789','VhSEZvOXVSdnlxTnpJcUE');

Parameters

NameTypeDescription
clientIdStringA client identifier.
signingKeyStringA private signing key.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.