Google地图加载两次 [英] Google Maps loading twice

查看:121
本文介绍了Google地图加载两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有特殊的情况,可以真正使用一些帮助。我有一个html构建器,每次刷新该网站时,都会添加其他脚本标记。这是一个严重的问题,因为我使用的是Google Maps API,并且每次刷新页面时都会添加以下脚本标记:

 < script src =https://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/19/main.jstype =text / javascript>< / script> 

不幸的是,这是我能够为这个项目开发页面的唯一方法。 (你可以想象我的沮丧>。)



基本上,如果这个脚本标记在html文档中存在多次,它会产生一个错误 Uncaught TypeError:Object#< Object>没有方法加载,这会阻止Google Maps API呈现我的地图。 我的问题:



有什么方法可以阻止Google API动态添加此脚本标记,或者在文档有机会加载它之前将其删除,或让文档完全忽略它?任何帮助都可以帮助我在今天早些时候睡一觉。)

解决方案

您不应该使用include。使用记录的包含

 < script type =text / javascript
src =https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY& ;传感器= SET_TO_TRUE_OR_FALSE>
< / script>

如果密钥是API控制台密钥并且不是必需的,并且传感器是否使用位置传感器或不是。

I have a special situation and could really use some help. I have an html builder and every time I refresh the site it adds additional script tags. This is a serious issue because I am using Google Maps API and it keeps adding the following script tag each time I refresh the page:

<script src="https://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/19/main.js" type="text/javascript"></script>

Unfortunately this is the only way I will be able to develop pages for this project. (You can imagine my frustration >.<).

Basically, if this script tag exists more than one time on the html document it raises an error Uncaught TypeError: Object #<Object> has no method 'Load' that prevents the Google Maps API from rendering my maps.

My question:

Is there any way I can prevent Google's API from dynamically adding this script tag, or remove it before the document has the opportunity to load it, or have the document completely ignore it? Any assistance will help me get to sleep a little earlier this morning :)

解决方案

You should not be using that include. Use the documented include:

 <script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE">
 </script>

Where the key is an API console key and is not required and the sensor is whether you are using a position sensor or not.

这篇关于Google地图加载两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆