【问题标题】:Fusion table query : zoom on a marker from an external link融合表查询:从外部链接放大标记
【发布时间】:2013-01-23 22:24:59
【问题描述】:

我正在尝试在谷歌融合地图中创建从文本到标记的链接。更准确地说,我希望地图刷新并放大所选位置。

一张图会更容易理解: http://projeteurope.free.fr/ 例如,如果您点击页面右侧的“Akrame”,地图应该会放大该点(融合表中已经存在,并且是 19 Rue Lauriston, 75016 Paris)

我查看了不同的主题和网站,但我不明白该怎么做(我是 javascript 的初学者) Fusion Table + Google Mapshttp://alamatku.com/cari?query=UPS&area=jakartaGoogle Fusion Tables With Maps - Link Table field to Map Info Window

我只想让地图放大特定市场,而不是创建一个只有标记的新图层。

如果您有任何线索,非常感谢! 罗宾

【问题讨论】:

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


    【解决方案1】:

    您可以使用GViz (the google visualization library)查询融合表并在标记处放大地图。

    代码:

    function changeQuery(term) {
      layer.setOptions({query:{select:'Latitude', /* was 'Latitude,Longitude', used to work... */
                               from:FT_TableID,
                               where:"Nom contains "+term
                               }
    
     });
    
      // zoom and center map on query results
      //set the query using the parameter
      var queryText = encodeURIComponent("SELECT 'Latitude', 'Longitude' FROM "+FT_TableID+" WHERE 'Nom' contains '"+term+"'");
      var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq='  + queryText);
    
      //set the callback function
      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 bounds = new google.maps.LatLngBounds();
      for(i = 0; i < numRows; i++) {
          var point = new google.maps.LatLng(
              parseFloat(response.getDataTable().getValue(i, 0)),
              parseFloat(response.getDataTable().getValue(i, 1)));
          bounds.extend(point);
      }
      // zoom to the bounds, if you have only one result, 
      // you may want to do a map.setCenter; map.setZoom to specify the behavior
      map.fitBounds(bounds);
    }
    

    example/proof of concept

    【讨论】:

    • 嗨 Geocodezip,Molle 博士,我正在根据 Dr.Molle 的建议在这个库上工作,但实际上我(真的)离结果还很远!非常感谢 Geocodezip!你很高兴实现这个例子。这正是我一直在寻找的。如果我可以问你更多的事情,我现在正试图让信息窗口在有人点击名字时自动打开。我已经查看了 developers.google.com/fusiontables/docs/samples/…,但我无法找到将代码放在哪里,因为它对我来说变得越来越复杂......无论如何还是非常感谢!
    • 如果你想从侧边栏点击打开信息窗口,我建议你自己实现点击监听器,并查询表格的内容。 Example
    • 您好 Geocodezip,感谢您的帮助。抱歉耽搁了,离开我的电脑有一段时间了……我现在正在处理它!
    • 大家好!如您所见(projeteurope.free.fr),我已经能够很好地实现第一部分,但是有一件愚蠢的事情:我无法输入包含 ' 的名称(例如在 L'ardoise 中)。我认为此时它会干扰代码:WHERE 'Nom' contains '"+term+"'")。我已经检查了其他标志并且它有效。如果您对此有任何想法,非常感谢...跨度>
    • 看起来像common problem,你有没有看过那些你可以使用的答案?
    猜你喜欢
    • 1970-01-01
    • 2014-09-25
    • 2014-03-06
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多