我有一個kml的點加載到融合表層。我想使用geoxml3解析數據到圖層範圍內的map.fitBounds,但那不是函數。下面的代碼正好用於KML多邊形,但不適用於KML點層。GeoXml3將kml(點)的融合表層分解成Google Maps
代碼:
var queryText = encodeURIComponent("SELECT * FROM 1CNJWjLDYgBkJGZVslJ67Fak4DyqadEFuIabzQ60 ");
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText);
query.send(zoomTo);
}
function zoomTo(response) {
if (!response) {
alert('no response');
return;
}
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
FTresponse = response;
//for more information on the response object, see the documentation
//http://code.google.com/apis/visualization/documentation/reference.html#QueryResponse
numRows = response.getDataTable().getNumberOfRows();
numCols = response.getDataTable().getNumberOfColumns();
var geoXml = new geoXML3.parser();
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < numCols; i++){
if (FTresponse.getDataTable().getColumnLabel(i) == 'geometry') {
var ColIndex = i;
}
}
if (!ColIndex){
alert('Geometry column "geometry" not found.')
}
for (var i = 0; i < numRows; i++){
var kml = FTresponse.getDataTable().getValue(i,ColIndex);
geoXml.parseKmlString("<Placemark>"+kml+"</Placemark>");
bounds.union(geoXml.docs[i].bounds);
}
map.fitBounds(bounds);
}
你在哪裏得到這個代碼?你能提供一個鏈接嗎?它看起來錯了。解析方法不應該用於從FusionTables解析KML字符串(parseKmlString方法用於這樣做)。 – geocodezip 2013-03-08 07:01:11
是的你是對的,它是我的錯。我編輯了代碼。現在它的工作。謝謝!我從www.geocodezip.com的例子中拿到了這段代碼。也許你可以在fusionlayer中添加一個標記kml的例子。 – 2013-03-08 14:09:45
我創建了一個[使用GViz和geoxml3]從FusionTables解碼KML「Points」的示例(http://www.geocodezip.com/geoxml3_test/v3_geoxml3_FusionTables_zoomToKmlMarkersA.html),我沒有使用您的數據,原因有兩個:1。您的表格未啓用下載2.您的表格有500行以上,並且在GViz查詢中運行到500行限制。 – geocodezip 2013-03-08 23:38:09