简体   繁体   中英

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"

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.

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?

Many thanks, Tony Reynolds

I would suggest updating the other parameters you're sending. Google Maps API currently requires 2 URL Params:

key : Your API key. The Maps JavaScript API will not load unless a valid API key is specified.

callback : The name of a global function to be called once the Maps JavaScript API loads completely.

An example of a valid API call would be

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

Also, the sensor parameter is no longer used and is recommended you should remove it.

Sources: URL Params , Versions , Sensor Param

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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