无法读取未定义的属性“查询”

时间:2013-05-14 13:57:00

标签: google-maps google-maps-api-3 google-fusion-tables google-visualization

在此代码段中 `

1) function gvizSelect(tableid) {
2)  var uri = "SELECT geometry FROM " + tableid + " WHERE name = 10095";
3)  var queryText = "http://www.google.com/fusiontables/gvizdata?tq=" + encodeURIComponent(uri);
4)  var query = new google.visualization.Query(queryText);
5)  query.send(getData);
6) }

`

我已经确认queryText url会在直接浏览时产生正确的响应集;但是第4行产生以下错误; “未捕获的TypeError:无法读取未定义的属性'查询'。”

这是一个完整的html文件,用于演示我收到的错误

<!DOCTYPE html>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Indianatrails.com</title>
  <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  <script type=text/javascript>
    google.load('visualization', '1', 
            {
              'packages':['corechart', 'table', 'geomap']
            }
    );
    var tableid = '1ZxSfeVZWVm_PuTe8Q5THFwmyR0NcGQzbSdCvQds';
    var uri = "SELECT geometry FROM " + tableid + " WHERE name = 10095";
    var queryText = "http://www.google.com/fusiontables/gvizdata?tq=" + encodeURIComponent(uri);
    var query = new google.visualization.Query(queryText);
    query.send(getData);
  </script>
  <body>
  <h1>Test</h1>
  </body>
</html>

我不知道(经过几天的阅读文档和示例),找出为什么这不起作用。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:3)

如果您使用的是google.load(),则需要等到脚本加载后再使用它。您可以设置回叫功能(google.setOnLoadCallback)。

  <script type=text/javascript>
    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(runQuery);
    google.load('visualization', '1', 
            {
              'packages':['corechart', 'table', 'geomap']
            }
    );
function runQuery() {
    var tableid = '1ZxSfeVZWVm_PuTe8Q5THFwmyR0NcGQzbSdCvQds';
    var uri = "SELECT geometry FROM " + tableid + " WHERE name = 10095";
    var queryText = "http://www.google.com/fusiontables/gvizdata?tq=" + encodeURIComponent(uri);
    var query = new google.visualization.Query(queryText);
    query.send(getData);
}
  </script>

当然,我得到一个错误,即没有定义getData(因为它不是)