Class Maps
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Google 地图
支持方向查找、地理编码、海拔采样和创建静态地图图片。
详细文档
decodePolyline(polyline)
将编码的多段线字符串解码回点数组。
// 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]);
}
参数
名称 | 类型 | 说明 |
polyline | String | 要解码的编码多段线。 |
返回
Number[]
- 纬度经度对的数组(lat0, long0, lat1, long1, ...)。
另请参阅
encodePolyline(points)
将点数组编码为字符串。
// 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);
参数
名称 | 类型 | 说明 |
points | Number[] | 要编码的纬度/经度对数组。 |
返回
String
- 表示这些点的编码字符串。
另请参阅
newGeocoder()
创建新的 Geocoder 对象。
返回
Geocoder
- 一个新的地理编码器对象。
newStaticMap()
创建新的 StaticMap 对象。
返回
StaticMap
- 一个新的静态映射对象。
setAuthentication(clientId, signingKey)
允许使用外部建立的 Google Maps API 高级计划账号,以利用额外的配额余额。您可以从 Google 企业支持门户获取客户端 ID 和签名密钥。将这些值设为 null
即可恢复使用默认配额。
Maps.setAuthentication('gme-123456789', 'VhSEZvOXVSdnlxTnpJcUE');
参数
名称 | 类型 | 说明 |
clientId | String | 客户端标识符。 |
signingKey | String | 私钥。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eThe Maps service facilitates tasks such as finding directions, geocoding addresses, sampling elevation data, and generating static map images.\u003c/p\u003e\n"],["\u003cp\u003eIt provides functionalities for encoding and decoding polylines, representing geographical coordinates.\u003c/p\u003e\n"],["\u003cp\u003eYou can create dedicated objects for direction finding, elevation sampling, geocoding, and static map creation.\u003c/p\u003e\n"],["\u003cp\u003eFor users with a Google Maps APIs Premium Plan, authentication can be set to utilize enhanced quota allowances.\u003c/p\u003e\n"]]],[],null,["# Class Maps\n\nMaps\n\nAllows for direction finding, geocoding, elevation sampling and the creation of static map\nimages. \n\n### Properties\n\n| Property | Type | Description |\n|---------------------|----------------------------------------------------------------------------|-------------|\n| `Direction``Finder` | [DirectionFinderEnums](/apps-script/reference/maps/direction-finder-enums) | |\n| `Static``Map` | [StaticMapEnums](/apps-script/reference/maps/static-map-enums) | |\n\n### Methods\n\n| Method | Return type | Brief description |\n|------------------------------------------------------------------------------|-------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [decodePolyline(polyline)](#decodePolyline(String)) | `Number[]` | Decodes an encoded polyline string back into an array of points. |\n| [encodePolyline(points)](#encodePolyline(Number)) | `String` | Encodes an array of points into a string. |\n| [newDirectionFinder()](#newDirectionFinder()) | [DirectionFinder](/apps-script/reference/maps/direction-finder) | Creates a new DirectionFinder object. |\n| [newElevationSampler()](#newElevationSampler()) | [ElevationSampler](/apps-script/reference/maps/elevation-sampler) | Creates an ElevationSampler object. |\n| [newGeocoder()](#newGeocoder()) | [Geocoder](/apps-script/reference/maps/geocoder) | Creates a new Geocoder object. |\n| [newStaticMap()](#newStaticMap()) | [StaticMap](/apps-script/reference/maps/static-map) | Creates a new StaticMap object. |\n| [setAuthentication(clientId, signingKey)](#setAuthentication(String,String)) | `void` | Enables the use of an externally established [Google Maps APIs Premium Plan](https://developers.google.com/maps/premium/) account, to leverage additional [quota allowances](https://developers.google.com/maps/premium/usage-limits). |\n\nDetailed documentation\n----------------------\n\n### `decode``Polyline(polyline)`\n\nDecodes an encoded polyline string back into an array of points.\n\n```javascript\n// Decodes a string representation of the latitudes and longitudes of\n// Minneapolis and Milwaukee respectively.\nconst polyline = 'qvkpG`qhxPbgyI_zq_@';\nconst points = Maps.decodePolyline(polyline);\nfor (let i = 0; i \u003c points.length; i += 2) {\n Logger.log('%s, %s', points[i], points[i + 1]);\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|----------|--------------------------------|\n| `polyline` | `String` | An encoded polyline to decode. |\n\n#### Return\n\n\n`Number[]` --- An array of latitude longitude pairs (lat0, long0, lat1, long1, ...).\n\n#### See also\n\n- [Encoded Polyline Format](/maps/documentation/utilities/polylinealgorithm)\n\n*** ** * ** ***\n\n### `encode``Polyline(points)`\n\nEncodes an array of points into a string.\n\n```javascript\n// The latitudes and longitudes of New York and Boston respectively.\nconst points = [40.77, -73.97, 42.34, -71.04];\nconst polyline = Maps.encodePolyline(points);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|------------|-------------------------------------------------|\n| `points` | `Number[]` | An array of latitude/longitude pairs to encode. |\n\n#### Return\n\n\n`String` --- An encoded string representing those points.\n\n#### See also\n\n- [Encoded Polyline Format](/maps/documentation/utilities/polylinealgorithm)\n\n*** ** * ** ***\n\n### `new``Direction``Finder()`\n\nCreates a new DirectionFinder object.\n\n#### Return\n\n\n[DirectionFinder](/apps-script/reference/maps/direction-finder) --- A new direction finder object.\n\n*** ** * ** ***\n\n### `new``Elevation``Sampler()`\n\nCreates an ElevationSampler object.\n\n#### Return\n\n\n[ElevationSampler](/apps-script/reference/maps/elevation-sampler) --- A new elevation sampler object.\n\n*** ** * ** ***\n\n### `new``Geocoder()`\n\nCreates a new Geocoder object.\n\n#### Return\n\n\n[Geocoder](/apps-script/reference/maps/geocoder) --- A new geocoder object.\n\n*** ** * ** ***\n\n### `new``Static``Map()`\n\nCreates a new StaticMap object.\n\n#### Return\n\n\n[StaticMap](/apps-script/reference/maps/static-map) --- A new static map object.\n\n*** ** * ** ***\n\n### `set``Authentication(clientId, signingKey)`\n\nEnables the use of an externally established [Google Maps APIs Premium Plan](https://developers.google.com/maps/premium/) account,\nto leverage additional [quota\nallowances](https://developers.google.com/maps/premium/usage-limits). Your client ID and signing key can be obtained from the Google Enterprise\nSupport Portal. Set these values to `null` to go back to using the default quota\nallowances.\n\n\n| **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 already have a Premium Plan license, please don't call [setAuthentication(clientId, signingKey)](#setAuthentication(String,String)). You are able to use the [Maps](#) methods with the default quota allowances.\n\n\u003cbr /\u003e\n\n```javascript\nMaps.setAuthentication('gme-123456789', 'VhSEZvOXVSdnlxTnpJcUE');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|----------------|----------|------------------------|\n| `client``Id` | `String` | A client identifier. |\n| `signing``Key` | `String` | A private signing key. |"]]