我浏览了this link,其中显示了带有自动完整搜索框的融合表地图图层。但是在这个例子中,只有前500行融合表在自动完成时进行索引。
找到下面的fiddle作为参考。
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来更新我的fiddle here,
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);
但无法实现自动完成。
答案 0 :(得分:1)
Google Visualization API is limited to 500 results from a FusionTable.
使用FusionTables v1 API instead,它没有这个限制。
代码的工作版本:
<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
});
};
答案 1 :(得分:0)
问题是您使用的是Google Visualization API来获取数据,并且限制为500行。通过JSONP的FT 1.0 API并不像@Swires所指出的那样。 请参阅此示例:https://developers.google.com/fusiontables/docs/samples/basic_jsonp_request