【问题标题】:GeoXml3 parse fusion table layer of kml (points) into Google MapsGeoXml3 将 kml(点)的融合表层解析为谷歌地图
【发布时间】: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


【解决方案1】:

parse 方法不应该用于解析来自 FusionTables 的 KML 字符串(parseKmlString 方法就是为了做到这一点)。

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

注意:存储在 FusionTables 中的 KML 片段不包含 geoxml3 查找的 &lt;Placemark&gt; 标签,这就是为什么将它们添加到传递给 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

【讨论】:

  • 您能否举例说明如何使用新的 FusionTables API 从 kml 中解析标记?
  • 是我还是 Fusion Table API 与 Visualization API 相比非常慢?尝试解析多边形 KML 真的很慢。
猜你喜欢
  • 2012-05-24
  • 2013-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多