简体   繁体   English

如何使用当前有效版本的谷歌地图 API?

[英]How can I use the google maps API with a currently-valid version?

I've got an app that incorporates google maps.我有一个包含谷歌地图的应用程序。 I call in the library with:我在图书馆打电话:

src="https://maps.googleapis.com/maps/api/js?v=[VERSION]&key=[MYKEY]&sensor=false" src="https://maps.googleapis.com/maps/api/js?v=[VERSION]&key=[MYKEY]&sensor=false"

It ran OK for a year or so then one day raised a script error.它运行了一年左右,然后有一天出现了脚本错误。 I found this was because the version number was out-of-date, so I increased it to the current version.我发现这是因为版本号过时了,所以我把它增加到当前版本。 Then about a year later it happened again.然后大约一年后,它又发生了。

This time I changed it to 'v=quarterly' which I was told would always use a current stable version.这次我将其更改为“v=quarterly”,我被告知将始终使用当前的稳定版本。

Today it's crashed again with the script error.今天它再次因脚本错误而崩溃。 Can anyone tell me how to always invoke a current and stable version of the API?谁能告诉我如何始终调用 API 的当前稳定版本?

Many thanks, Tony Reynolds非常感谢,托尼·雷诺兹

I would suggest updating the other parameters you're sending.我建议更新您发送的其他参数。 Google Maps API currently requires 2 URL Params:谷歌地图 API 目前需要2 个 URL 参数:

key : Your API key. key :您的 API 密钥。 The Maps JavaScript API will not load unless a valid API key is specified.地图 JavaScript API 将不会加载,除非指定了有效的 API 密钥。

callback : The name of a global function to be called once the Maps JavaScript API loads completely. callback :一旦地图 JavaScript API 完全加载,将调用全局 function 的名称。

An example of a valid API call would be一个有效的 API 调用的例子是

<script async
    src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>

The version key is not required, and would default to weekly , but if you specify v=quarterly it will only use larger, less frequent updates. version 密钥不是必需的,默认为weekly ,但如果您指定v=quarterly它将只使用更大、更不频繁的更新。

Also, the sensor parameter is no longer used and is recommended you should remove it.此外,传感器参数不再使用,建议您将其删除。

Sources: URL Params , Versions , Sensor Param资料来源: URL 参数版本传感器参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM