【发布时间】:2013-03-07 21:31:08
【问题描述】:
我有一个 kml 点加载到融合表层中。我想使用geoxml3将数据解析为图层范围上的une map.fitBounds,但这不起作用。下面的这段代码适用于 KML 多边形,但不适用于 KML 点图层。
代码:
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);
}
【问题讨论】:
-
你从哪里得到这个代码?你能提供一个链接吗?看起来不对。 parse 方法不应该用于解析来自 FusionTables 的 KML 字符串(parseKmlString 方法就是为了做到这一点)。
-
是的,你是对的,这是我的错误。我编辑了代码。现在它的工作。谢谢你! p.s 我从您在 www.geocodezip.com 的示例中获取了此代码。也许您可以在 fusiontablelayer 中添加一个带有标记 kml 的示例。
-
我创建了一个example that decodes KML "Points" from FusionTables using GViz and geoxml3,我没有使用您的数据有两个原因:1.您的表未启用下载 2.您的表有超过 500 行,并且运行到 500 GViz 查询的行限制。
-
谢谢。幸好你没有使用我的数据,我不能保证它会在线很长时间。
标签: google-maps kml google-fusion-tables