融合表自动完成文本搜索

用户3102065

我浏览了此链接,其中显示了带有自动完成搜索框的融合表地图图层。但是在此示例中,只有自动融合的索引表中的前500行在自动完成中建立了索引。

查找下面小提琴以供参考。

  function initAutoComplete(tableId) {
    // Retrieve the unique store names using GROUP BY workaround.
    var queryText = encodeURIComponent(
        "SELECT 'FB_INDO_2000', COUNT() " +
        'FROM ' + tableId + " GROUP BY 'FB_INDO_2000'");
    var query = new google.visualization.Query(
        'http://www.google.com/fusiontables/gvizdata?tq='  + queryText);

    query.send(function(response) {
      var numRows = response.getDataTable().getNumberOfRows();

      // Create the list of results for display of autocomplete.
      var results = [];
      for (var i = 0; i < numRows; i++) {
        results.push(response.getDataTable().getValue(i, 0));
      }

      // Use the results to create the autocomplete options.
      $('#store').autocomplete({
        source: results,
        minLength: 2
      });
    });
  }

编辑:正如geocodezip建议的那样,我在这里通过将查询更改为FT API v1来更新了我的小提琴

var queryText = encodeURIComponent(
        "SELECT 'FB_INDO_2000', COUNT() " + 'FROM ' + tableId + " GROUP BY 'FB_INDO_2000'");
     var queryUrlHead = 'https://www.googleapis.com/fusiontables/v1/query?sql=';
    var queryUrlTail = '&key=AIzaSyCAI2GoGWfLBvgygLKQp5suUk3RCG7r_ME';
    var query = new google.visualization.Query(queryUrlHead + queryText + queryUrlTail);

但是无法实现自动完成。

地理编码

谷歌可视化API仅限于从FusionTable 500个结果。

改为使用FusionTables v1 API,它没有该限制。

您的代码的工作版本:

<script src="https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20'FB_INDO_2000'%20FROM%201E9BosnI16GISRmTBkINI2aWlYVdZae46v8jClAc%20GROUP%20BY%20'FB_INDO_2000'&callback=drawMap&key=AIzaSyCAI2GoGWfLBvgygLKQp5suUk3RCG7r_ME" type="text/javascript" ></script>

   function drawMap(response) {
      var numRows = response.rows.length;

      // Create the list of results for display of autocomplete.
      var results = [];
      for (var i = 0; i < numRows; i++) {
        results.push(response.rows[i][0]);
      }

      // Use the results to create the autocomplete options.
      $('#store').autocomplete({
        source: results,
        minLength: 2
      });
   };

工作小提琴

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章