支持方向查找、地理编码、海拔采样和创建静态地图图片。
属性
| 属性 | 类型 | 说明 |
|---|---|---|
Direction | Direction | |
Static | Static |
方法
| 方法 | 返回类型 | 简介 |
|---|---|---|
decode | Number[] | 将编码的多段线字符串解码回点数组。 |
encode | String | 将点数组编码为字符串。 |
new | Direction | 创建新的 DirectionFinder 对象。 |
new | Elevation | 创建 ElevationSampler 对象。 |
new | Geocoder | 创建新的 Geocoder 对象。 |
new | Static | 创建新的 StaticMap 对象。 |
reset | void | 重置身份验证凭据以使用默认配额。 |
set | void | 启用使用 API 密钥对请求进行身份验证,以利用额外的配额。 |
set | void | 支持使用 API 密钥和签名密钥对请求进行身份验证,以便在 StaticMap 中利用额外的配额。 |
详细文档
decode Polyline(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...)。
另请参阅
encode Polyline(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 - 表示这些点的编码字符串。
另请参阅
new Direction Finder()
new Elevation Sampler()
new Geocoder()
new Static Map()
reset Authentication Api Key()
重置身份验证凭据以使用默认配额。当您使用 API 密钥对请求进行身份验证时,此方法会生效。如果您想在不提供身份验证凭据的情况下使用 Maps 方法,可以使用此方法恢复为默认配额限额。
Maps.resetAuthenticationApiKey();
抛出
Error - 如果 用于身份验证。set
set Authentication By Api Key(apiKey)
启用使用 API 密钥对请求进行身份验证,以利用额外的配额。
此方法用于设置用于对请求进行身份验证的 API 密钥。调用此方法时,系统会根据价目表,将配额用量和结算费用计入与所提供的 API 密钥关联的 Google Cloud 项目。您可以使用默认配额限额的 Maps 方法,而无需提供身份验证凭据。如果您使用的是 StaticMap,请改用 set 方法。
Maps.setAuthenticationByApiKey('BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
api | String | API 密钥,可通过按照快速入门指南中所述的步骤从 Google Cloud 控制台中获取。 |
抛出
Error - 如果 api 为 null,或者 已用于身份验证set
set Authentication By Api Key(apiKey, signingKey)
启用 API 密钥和签名密钥的使用,以对请求进行身份验证,从而在 StaticMap 中利用额外的配额。虽然 signing 是对 Static Map API 发出请求所必需的,但此方法也可用于对其他 Google 地图服务进行身份验证。在这些情况下,系统会忽略 signing 参数。
此方法用于设置 API 密钥和签名密钥,以对请求进行身份验证。StaticMap 需要签名密钥,它在测试时接受少量无签名的请求,但一旦达到生产环境中的阈值,这些请求就会开始失败。如需了解详情,请点击此处。
Maps.setAuthenticationByApiKey('BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0', '7_pry-Skg0PKxds-7nvdl91mB5=');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
api | String | API 密钥,可通过按照快速入门指南中所述的步骤从 Google Cloud 控制台中获取。 |
signing | String | 签名密钥,可通过按照数字签名指南中所述的步骤从 Google Cloud 控制台获取。对于 StaticMap,此参数是必需的;对于其他地图服务,此参数会被忽略。 |
抛出
Error - 如果 api 为 null,或者 已用于身份验证set