GeoXml3解析融合表层的kml(点)进入谷歌地图

时间:2013-03-07 21:31:09

标签: google-maps kml google-fusion-tables

我有一个kml点加载到融合表层。我想使用geoxml3将数据解析为图层范围上的map 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);
    }

1 个答案:

答案 0 :(得分:1)

parse方法不应该用于解析来自FusionTables的KML字符串(parseKmlString方法用于执行此操作)。

      var kml = FTresponse.getDataTable().getValue(i,ColIndex);
      geoXml.parseKmlString("<Placemark>"+kml+"</Placemark>");

注意:存储在FusionTables中的KML片段不包含geoxml3寻找的<Placemark>标签,这就是为什么它们被添加到传递给geoxml3的字符串中。

GViz查询响应有500行限制(似乎没有记录在我找到的任何地方,我能找到的最好的是reference to it,但文档已经移动了。)

看起来你会遇到你的桌子的限制,要克服使用FusionTables API v1.0,返回GeoJSON,而不是KML(所以你不再需要geoxml3)。

example that decodes KML "Points" from FusionTables using GViz and geoxml3(表格少于500分)

example of parsing markers from Fusion Tables using the Fusion Tables API v1.0