SQL Great Circle Distance with fusion table

时间:2012-11-30 04:08:05

标签: google-maps-api-3

我在使用地理编码器和融合表时搜索位置半径函数有困难,其中列X和Y存储长lat。实际上问题出在查询的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);
   }
 });
}

1 个答案:

答案 0 :(得分:1)

使用ST_INTERSECTS

3218米是圆的半径。

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

Working Example