我正在尝试显示基于地理编码事件呈现它们的 Google Fusion Table 中的点。该事件以地图为中心,显示一个标记,但我希望它根据新的地图中心和固定半径在表格上进行新的选择。我的尝试是将变量传递给空间查询,但我不确定将它放在哪里或者我是否正确调用它。
就此而言,即使只使用 onClick 事件来触发新查询也会很酷,但这是同样的问题。
在此先感谢...拉法
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Selected Records from Google Fusion Table based on Geocoded Location</title>
<style>
body { font-family: Arial, sans-serif; }
#map_canvas { height: 600px; width:700px; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var layer;
var geocoder;
var map;
var tableid = 411675;
// initialize the map =====================
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(45.526, -122.6684);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
layer = new google.maps.FusionTablesLayer(tableid);
layer.setMap(map);
}
// operates geocoder =====================
function codeAddress() {
var gcAddress = document.getElementById("gcAddress").value;
geocoder.geocode( { 'address': gcAddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
layer.setQuery("SELECT Address FROM " + tableid + " WHERE ST_INTERSECTS(Address, CIRCLE(LATLNG(" + position + "), 5000))");
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
</head>
<body onload="initialize();">
<div>
<input id="gcAddress" type="textbox" value="Hillsboro, OR">
<input type="button" value="Geocode" onclick="codeAddress()">
</div>
<div id="map_canvas"></div>
</body>