0

我正在尝试显示基于地理编码事件呈现它们的 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>
4

1 回答 1

0

我想你的表达方式可能有点错误。

var query = "SELECT Address FROM " + tableid + " WHERE ST_INTERSECTS(Address, CIRCLE(LATLNG" + marker.position + ", 20000))";

我更新了位置以读取marker.position,删除了自带的括号。然后我将半径扩大到 20000 以进行测试。

这对我有用。如果您需要测试查询,您可以使用一个示例,例如

http://kh-samples.googlecode.com/svn/trunk/talks/samples/fusiontableslayer.html

作为测试的基础(只需为您的表格保存和修改它),希望能帮助捆绑:)

希望这可以帮助。

马特

于 2011-01-31T10:15:52.647 回答