我已经阅读了许多与我相关的问题,我尝试了很多解决方案,但代码仍无效。
当我点击地图时,我有所需的结果(多边形的名称),但当我查询表时没有任何反应。
我做错了什么?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253">
<meta http-equiv="Content-Language" content="el">
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
<title></title>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDZbke25XIzzLt04B93oaJdESKE3lbrgAM&v=3.exp&sensor=false&libraries=places&callback=initMap" async defer></script>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 38.0010, lng: 23.8743},
zoom: 5,
disableDefaultUI: true,
zoomControl: true
});
layer = new google.maps.FusionTablesLayer({
map: map,
heatmap: { enabled: false },
query: {
select: "col2",
from: "1Bf6zLV8tWlmdqGAt5lMvVmPZ-b47szjMEjwmJGc9",
where: ""
},
options: {
styleId: 2,
templateId: 2
}
});
}
function getname(latlng){
alert(latlng);
var queryStr = [];
queryStr.push("SELECT name ");
queryStr.push(" FROM " + '1Bf6zLV8tWlmdqGAt5lMvVmPZ-b47szjMEjwmJGc9');
// set coordinates and tolerance radius
queryStr.push(" WHERE ST_INTERSECTS(geometry, CIRCLE(LATLNG("+latlng+"), 1))");
var sql = encodeURIComponent(queryStr.join(" "));
// try complete query here
//var sql="SELECT name FROM 1Bf6zLV8tWlmdqGAt5lMvVmPZ-b47szjMEjwmJGc9 WHERE ST_INTERSECTS(geometry,CIRCLE(LATLNG(38.0010,23.8743),1))";
$.ajax({
url: "https://www.googleapis.com/fusiontables/v2/query?sql="+sql+"&key="+"AIzaSyDZbke25XIzzLt04B93oaJdESKE3lbrgAM",
dataType: "json"
}).done(function (response) {
document.getElementById("prefecture").value = response.rows[0][0];
});
}
</script>
<style>
#map {
width: 100%;
height: 350px;
}
</style>
</head>
<body>
<div id="map"></div>
<input type="text" Name="prefecture" id="prefecture">
<input type="button" value="GetName" name="B1" onClick="getname('38.0010,23.8743');">
</body>
</html>