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

编辑:当我删除'其中'时,知道地图显示正确可能会有所帮助。子句(这使我相信查询是问题)。我忘了提到我为图层分配了如下图:
$("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...
});

答案 0 :(得分:0)
您需要设置FusionTablesLayerOptions的map
属性(或者至少在某个时候设置它):
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
});
代码段
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;