gpt4 book ai didi

javascript - 要访问 Google maps api,我什么时候需要使用以下脚本?

转载 作者:行者123 更新时间:2023-11-30 12:04:31 24 4
gpt4 key购买 nike

<script type="text/javascript" src="http://maps.google.com/maps/api/js"></script>

and

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

n the above scripts, the difference is API key. I have noticed code samples working with and without API KEY. It says Google Maps Javascript API 2 requires API key and Google Maps Javascript API 3 doesn't require the key. But in the scripts we are not mentioning which version of API it should access. So what makes the difference?

最佳答案

此脚本加载 experimental version没有 API key 的 Google Maps Javascript API:

<script type="text/javascript" src="http://maps.google.com/maps/api/js"></script>

此脚本使用 API key 异步加载 Google Maps Javascript API 的实验版本:

<script async defer  src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">   </script>
  • API key 允许跟踪使用情况,并允许您在需要时购买额外的配额。

对于async defercallback参数,来自这个问题的答案:Page speed - any problems with simply using defer attribute?

async: You can prevent a script from blocking during load by using the async attribute on modern browsers

defer: The defer attribute indicates not to load at all until the page DOM has completely loaded. Defer implies async.

With the Google Maps API, you must use a callback parameter when loading the API asynchronously. This causes the api to use dynamic script insertion rather than document.write calls internally. You can specify an empty callback parameter as well.

关于javascript - 要访问 Google maps api,我什么时候需要使用以下脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35604539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com