2013-12-23 32 views
0

我通過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作爲,

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); 

但無法實現自動完成我的fiddle here

回答

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 
     }); 
    }; 

working fiddle

+0

我自己修改我的小提琴到FT API v1在這裏:http://jsfiddle.net/HnwA2/3/但自動完成不起作用。我錯在哪裏? – user3102065

+0

您沒有正確使用Fusion Tables v1 API(您仍在使用google.visualization.Query調用,您需要用等價的v1調用替換它)。 [使用FT v1 API的示例](http://www.geocodezip.com/v3_GoogleEx_FusionTables_generic_JSON_linkto.html?lat=48.470294&lng=-119.353782&zoom=2&type=m&tablequery=SELECT%20%20kml_4326%,%name%20FROM&tableid=1foc3xO9DyfSIF6ofvN0kp2bxSfSeKog5FbdWdQ&where=name %20包含%20%27國家%27) – geocodezip

+1

更新我的答案與工作小提琴(和代碼,使其工作) – geocodezip