1

我在使用地理编码器和 X 列和 Y 列存储长纬度的融合表时遇到了搜索位置半径函数的困难。实际上问题出在查询的 WHERE 条件中。如果可以调试,谢谢。这是我的功能:

function CP_query() {
  CPsearch = document.getElementById('CP_Input').value;
  geocoder.geocode( { 'address': CPsearch}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      mylat = results[0].geometry.location.lat();
      mylon = results[0].geometry.location.lng();
      //alert("lat : " + mylat + "long: " + mylon);
      layer_imm = new google.maps.FusionTablesLayer({
          query: {
              select: 'geometry',
              from: '1ckqpE8ZxVzfgJ5bT-vAkpBwjVANbV-KiNjfScjw',
              where: '6371 * acos( cos( radians(' + mylat + ') ) * cos( radians( Y ) ) * cos( radians( X ) - radians(' + mylon + ') ) + sin( radians(' + mylat + ') ) * sin( radians( Y ) ) ) < 2'
           }
       }); 
       layer_imm.setMap(map);
       map.setCenter(results[0].geometry.location);
       var marker = new google.maps.Marker({
       map: map,
       position: results[0].geometry.location
       });
   } else {
     alert("Geocode was not successful for the following reason: " + status);
   }
 });
}
4

1 回答 1

1

使用ST_INTERSECTS

3218米是圆的半径。

query: {
  select:'geometry'
  from:  '1ckqpE8ZxVzfgJ5bT-vAkpBwjVANbV-KiNjfScjw',
  where: 'ST_INTERSECTS(geometry,CIRCLE(LATLNG('+ mylat + ',' + mylon + '), 3218))'
}

工作示例

于 2012-11-30T04:38:13.323 回答