为什么一个简单的google.load('可视化....调用抛出错误?

时间:2015-01-15 21:15:50

标签: javascript google-visualization

我只是想加载google可视化软件包,这样我就可以查询Fusion Table来查找一些地图边界。

以下是导致问题的四行代码:

   <script src="https://www.google.com/jsapi"></script>
   <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
   <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script><script>

    google.load('visualization', '1', {'packages':['corechart', 'table', 'geomap']}, callback:function() { alert('!'); }});

如果我发表评论google.load,一切都很好,但除非从此工作代码示例中复制,否则上述内容无效:Google Maps API - Zoom to Fusion Table Layer Query Results

最终我想从参考SO帖子中实现zoomTo()函数,但是如果没有我的所有javascript失败,我甚至无法运行google.load函数。

scriptInjector.js:188 sI: about to establish extension connection for WIDGET_CONTENT_MESSAGE - url: http://gfsfshfs8/hmap.php
scriptInjector.js:191 sI: adding WIDGET_CONTENT_MESSAGE message listener
reservespaceifenabled.js:5 rsie: reserveSpace
reservespaceifenabled.js:7 rsie: getToolbarData
reservespaceifenabled.js:66 rsie: leaving js
hmap.php:99 Uncaught SyntaxError: Unexpected token :
reservespaceifenabled.js:15 rsie: getToolbarDataCallback(Arguments[1])
reservespaceifenabled.js:25 rsie: window.toolbarData: Object
reservespaceifenabled.js:26 rsie: window.Content: undefined
reservespaceifenabled.js:35 rsie: getToolbarDataCallback - done
contentScript.js:42 cS: logger: Array[1] : undefined
contentScript.js:42 cS: logger: Array[1]0: Array[1]length: 1__proto__: Array[0] : undefined
contentScript.js:42 cS: logger: Array[1] : document ready
contentScript.js:42 cS: logger: Array[1] : running callback
contentScript.js:42 cS: logger: Array[1] : undefined
contentScript.js:42 cS: logger: Array[1] : firing tab complete
contentScript.js:80 cS: sending TAB_COMPLETE

1 个答案:

答案 0 :(得分:0)

您正在导入不正确的Google JS包。您导入的地图API不包含可视化包。将您的谷歌导入更改为:

<script src="https://www.google.com/jsapi</script>

它应该有效。这是一个有效的JSFiddle