我最近收到了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和回调参数。两者都产生相同的结果。
感谢您的协助。
addInfoWindow() *
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);
}
}
更新:generateInfoWindow()
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");
}
}
答案 0 :(得分:0)
尝试类似:“...)& key =”+ apiKey +“& callback = addInfoWindow()”
答案 1 :(得分:0)
这里有一些示例代码,专注于从Fusion Table检索数据。 https://docs.google.com/file/d/0B5KVZ6J1ohN_dktpWXBmSzNkdjg/edit
我猜你不想要这部分:),0.1)) ......而且你确实需要API密钥。
希望有所帮助,
-Rebecca