我使用Google Maps API 3.0中的一些代码和Fusion表'向导'中的一些代码组合了一张地图。在我的网站中,地图的标记立即更新融合表中的任何新地址数据,但信息窗口(无论是自定义还是使用Fusion Tables中的自动选项)都不会。这里缺少什么?
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDOQ7cOkzKuRSXdaZnJjmzf286-rU9Tb1w"></script>
<script type="text/javascript">
function initialize() {
var defaultCenter = new google.maps.LatLng(51.514462083331054, -0.16631473222648907);
var defaultZoom = 9;
var tableId = '1gBco4IwW3QVelKt9fpY11auhGnm-bu-fNe_9bbvv';
var locationColumn = 'col4';
var geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: defaultCenter,
zoom: defaultZoom,
panControl: false,
zoomControl: true,
scaleControl: true,
mapTypeControl: false,
streetViewControl: false,
scrollwheel: false
});
mapTypeId: google.maps.MapTypeId.ROADMAP
var layer = new google.maps.FusionTablesLayer({
query: {
select: locationColumn,
from: tableId
},
map: map
});
var zoomToAddress = function() {
var address = document.getElementById('address').value;
geocoder.geocode({
address: address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(13);
} else {
window.alert('Address could not be geocoded: ' + status);
}
});
};
google.maps.event.addDomListener(document.getElementById('search'),'click', zoomToAddress);
google.maps.event.addDomListener(window, 'keypress', function(e) {
if (e.keyCode == 13) {
zoomToAddress();
}
});
google.maps.event.addDomListener(document.getElementById('reset'),
'click',
function() {
map.setCenter(defaultCenter);
map.setZoom(defaultZoom);
layer.setOptions({
query: {
select: locationColumn,
from: tableId
}
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
答案 0 :(得分:0)
您必须指定templateId
,否则将根据默认模板(包含所有列)创建InfoWindow
var layer = new google.maps.FusionTablesLayer(
{
query:
{
select: locationColumn,
from: tableId
},
options:
{ //a custom template
//created by someone
//which omits the 'Household Street'
templateId: 3
},
map: map
});