Javascript 使用GoogleMapsAPI 3.0和FusionTablesAPI 1.0检索InfoWindowContent
我最近收到一封来自谷歌的电子邮件,建议我更新地图代码。我遵循了他们网站上的指示。现在除了信息窗口外,所有功能都正常运行。当我键入地址并点击搜索时,它会正确地将pin码放在地图上,但不会打开包含相应内容的信息窗口。这是我认为不正确的代码片段Javascript 使用GoogleMapsAPI 3.0和FusionTablesAPI 1.0检索InfoWindowContent,javascript,json,google-maps-api-3,google-fusion-tables,infowindow,Javascript,Json,Google Maps Api 3,Google Fusion Tables,Infowindow,我最近收到一封来自谷歌的电子邮件,建议我更新地图代码。我遵循了他们网站上的指示。现在除了信息窗口外,所有功能都正常运行。当我键入地址并点击搜索时,它会正确地将pin码放在地图上,但不会打开包含相应内容的信息窗口。这是我认为不正确的代码片段 var script = document.createElement("script"); script.setAttribute("src","https://www.googleapis.com/fusiontables/v1/query?sq
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和回调参数。两者产生相同的结果
谢谢你的帮助
AddInfo窗口()*
}
更新:生成信息窗口()
}试试类似的方法:“…)&key=“+apiKey+”&callback=AddInfo窗口()”下面是一些示例代码,重点介绍如何从融合表中检索数据。 我猜你不想要这个部分:),0.1) ... 您确实需要API密钥 希望有帮助
-Rebecca将jsonCallback更改为回调。另外,请发布回调函数的代码
addinfo window()
谢谢@Marcelo。我已经相应地更新了。仍在处理这个问题,@Marcelo。我已经调整了几次SQL调用,但都没有成功。现在,整个函数都发布在我的问题中。如果您能再作一次审查,我将不胜感激。谢谢谢谢,埃里克。我已经更新了剧本,但问题仍然存在。谢谢,@Rebecca。我已经相应地更新了,运气不好。我已经添加了整个GenerateInfo窗口()。我确实从ST_INTERSECTS删除了.1。谢谢你的帮助!
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");
}