如何动态加载谷歌地图库 [英] How to load google maps libraries dynamically
问题描述
我知道我可以使用在google maps api v3中加载库, URL中的库
参数。现在我处于无法更改html标记的情况下,只有javascript。 Google地图库可以使用JavaScript调用动态加载,例如通过调用一些谷歌API功能?例如。类似于 google.load()
。
是相当老,但我最近有同样的问题。在我的情况下,我无法轻易更改脚本加载url,但后来添加js代码。 Double loading google-maps-js无法解决问题,因为它被google禁止。
为了使用库,我复制了我需要的代码块网址。对于加载地点,它看起来像:
转到: https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&language=de&libraries=places
并复制最后一块,如下所示:
google.maps。 __gjsload __('places',function(_){...})
将其包含在您的脚本中加载默认api后。
记住:这很脏,但可以解决您的一些问题。干杯!
I know I can load libraries in google maps api v3 using libraries
argument in URL. Now I am in the situation where I cannot change the html markup, only javascript. Can google maps libraries be loaded dynamically using some javascript call, e.g. by calling some google api function? E.g. something like google.load()
.
I know this question is rather old, but I had the same problem recently. In my case I couldn't easily change the script-load-url but attach js-code afterwards. Double loading google-maps-js couldn't solve the problem as well beecause it is prohibited by google.
To use libraries I copied the code blocks I needed from the respective urls. For loading places it has looked like:
goto: https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&language=de&libraries=places
and copy'paste the last block which looks like:
google.maps.__gjsload__('places', function(_){ ... })
include it in your script after loading the default api.
Remember: This is rather dirty but could solve problems for some of you. Cheers!
这篇关于如何动态加载谷歌地图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!