我最近收到了一封来自 Google 的电子邮件,建议我更新我的地图代码。我按照他们的Migration Guide中提供的说明进行操作。现在一切正常,除了 infoWindow。当我输入地址并点击搜索时,它会正确地将图钉放在地图上,但不会打开具有相应内容的 infoWindow。这是我认为不正确的代码片段。
var script = document.createElement("script");
script.setAttribute("src","https://www.googleapis.com/fusiontables/v1/query?sql=SELECT * FROM " +
tableid + " WHERE ST_INTERSECTS(geometry, CIRCLE(LATLNG(" + coordinate.lat() + "," + coordinate.lng() + "), 0.1))&jsonCallback=addInfoWindow");
document.getElementsByTagName("head")[0].appendChild(script);
我已经尝试了 jsonCallback 和回调参数。两者产生相同的结果。
谢谢您的帮助。
添加信息窗口()*
function addInfoWindow(response) {
infowindow.close();
if(response.table.rows.length) {
infowindow.close();
initialize();
infowindow.setContent("Content removed: " + response.table.rows[0][1] + response.table.rows[0][0]);
infowindow.setPosition(coordinate);
map.setCenter(coordinate);
map.setZoom(15);
infowindow.open(map);
}
else
{
infowindow.close();
initialize();
infowindow.setContent("Nothing here.");
infowindow.setPosition(coordinate);
map.setCenter(coordinate);
map.setZoom(15);
infowindow.open(map);
}
}
更新:生成信息窗口()
function generateInfoWindow(results, status) {
initialize();
if (status == google.maps.GeocoderStatus.OK) {
initialize();
//center and zoom map
coordinate = results[0].geometry.location;
marker = new google.maps.Marker({
map: map,
layer: layer,
animation: google.maps.Animation.DROP,
position: coordinate
});
map.setCenter(results[0].geometry.location);
map.setZoom(15);
var script = document.createElement("script");
script.setAttribute("src","https://www.googleapis.com/fusiontables/v1/query?sql=SELECT * FROM " +
tableid + " WHERE ST_INTERSECTS(geometry, CIRCLE(LATLNG(" + coordinate.lat() + "," + coordinate.lng() + ")))&key=" + apiKey + " &callback=addInfoWindow()");
document.getElementsByTagName("head")[0].appendChild(script);
} else {
alert("Please make sure you entered your City and State");
}
}