如何检查 Google Maps API 是否已加载? [英] How to check if Google Maps API is loaded?
本文介绍了如何检查 Google Maps API 是否已加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查是否加载了 Google Maps API (v3)?
How to check if Google Maps API (v3) is loaded?
如果 API 由于互联网连接问题(网页在本地托管)而未加载,我不想执行映射脚本.
I do not want to execute mapping scripts if the API did not load due to internet connectivity problems (web page is hosted locally).
推荐答案
if (google.maps) {...}
如果 google 未定义(即如果 API未加载).
if (google.maps) {...}
will give you a reference error if google is undefined (i.e. if the API didn't load).
相反,使用 if (typeof google === 'object' && typeof google.maps === 'object') {...}
来检查它是否加载成功.
Instead, use if (typeof google === 'object' && typeof google.maps === 'object') {...}
to check if it loaded successfully.
这篇关于如何检查 Google Maps API 是否已加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文