Google Fusion桌面查询使用FusionTablesLayerOptions'查询参数不起作用

时间:2016-07-28 17:49:41

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

我的目标是根据Fusion Table查询的结果创建一个google.maps.FusionTablesLayer。我有一个公开的Google Fusion Table已经"已启用下载"。我可以使用Google Fusion Tables REST API成功查询表格,如下所示(我会提供API链接,但没有足够的声誉)。以下查询适用于浏览器:

https://www.googleapis.com/fusiontables/v2/query?sql=SELECT+start_lat+,+dir+FROM+1JUAkUL5H7IhU4QrmLuVQ65Tg2SNyI5Xqm3A7Nk1g+WHERE+dir=%27Northbound%27&key=AIzaSyBCjde_rx_Fe0v4G_vD-uI33M1o9toMF2A

我真正想要的是能够使用查询结果创建Google Fusion Tables Layer对象。似乎最简单的方法是在初始化Google Fusion Tables Layer对象期间将上述查询作为参数提供(如JavaScript FusionTablesLayer API中所示)。但是,FusionTablesLayer在初始化期间查询时无法显示如下:



northbound_hikers_start_layer = new google.maps.FusionTablesLayer({
  query: {
    select: 'start_lat',
    from: '1JUAkUL5H7IhU4QrmLuVQ65Tg2SNyI5Xqm3A7Nk1g',
    where: "dir = 'Northbound'"
  },
  heatmap: {
    enabled: true
  },
  suppressInfoWindows: false
});



 我无法理解为什么'哪里有'将查询作为参数传递给FusionTablesLayer对象时,子句失败,但Fusion Tables REST API查询在浏览器中工作正常。我已阅读API,但有关此特定主题的页面却出乎意料地不完整。有任何想法吗?我希望我可以包含更多指向我正在使用的特定API的链接,但我的StackOverflow信誉不足以发布超过2个网址。最终目标是FusionTablesLayer,只包含查询获得的数据。

编辑:当我删除'其中'时,知道地图显示正确可能会有所帮助。子句(这使我相信查询是问题)。我忘了提到我为图层分配了如下图:



 $("button").click(function() {
   console.log(this.id + " button was pressed.");
   if (this.id == "toggle-at-centerline-button") {
     //Toggle AT Centerline Layer
     if (!toggle_at_centerline_button_pressed) {
       centerline_layer.setMap(map);
       toggle_at_centerline_button_pressed = true;
     } else {
       centerline_layer.setMap(null);
       toggle_at_centerline_button_pressed = false;
     }
   } else if (this.id == "toggle-at-shelter-button") {
     //Toggle AT Shelters Layer
     if (!toggle_at_shelter_button_pressed) {
       shelterLayer.setMap(map);
       toggle_at_shelter_button_pressed = true;
     } else {
       shelterLayer.setMap(null);
       toggle_at_shelter_button_pressed = false;
     } etc...
});




1 个答案:

答案 0 :(得分:0)

您需要设置FusionTablesLayerOptionsmap属性(或者至少在某个时候设置它):

var northbound_hikers_start_layer = new google.maps.FusionTablesLayer({
  query: {
    select: 'start_lat',
    from: '1JUAkUL5H7IhU4QrmLuVQ65Tg2SNyI5Xqm3A7Nk1g',
    where: "dir = 'Northbound'"
  },
  heatmap: {
    enabled: true
  },
  suppressInfoWindows: false,
  map: map
});

proof of concept fiddle

代码段



function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(39.232253, -76.640625),
      zoom: 4,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  var northbound_hikers_start_layer = new google.maps.FusionTablesLayer({
    query: {
      select: 'start_lat',
      from: '1JUAkUL5H7IhU4QrmLuVQ65Tg2SNyI5Xqm3A7Nk1g',
      where: "dir = 'Northbound'"
    },
    heatmap: {
      enabled: true
    },
    suppressInfoWindows: false,
    map: map
  });
}
google.maps.event.addDomListener(window, "load", initialize);

html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}

<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>
&#13;
&#13;
&#13;