谷歌融合表&地图-检测区域中的地址

Google Fusion Tables & Maps - Detect address in region

本文关键字:区域 检测 地址 地图 融合 amp 谷歌      更新时间:2023-09-26

因此,我目前将Fusion表设置为KML中的区域地图。我还按地址进行了搜索。我需要能够输入地址,搜索,并确定该点在哪个"地区"。这可能吗?提前谢谢。

您可以使用一点JavaScript代码来完成此操作。首先,听起来搜索框在工作。您需要对输入到地址搜索中的地址进行地理编码。然后,您可以使用结果的lat/lon坐标执行相交查询,以查找融合表中位于输入地址的极小半径(例如0.0001米)内的所有特征。下面的示例代码:

<html>
  <head>
    <script type="text/javascript"
        src="http://maps.google.com/maps/api/js?v=3.2&sensor=false&region=US">
    </script>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      var map, layer;
      var geocoder = new google.maps.Geocoder();
      var tableid = 297050;
      google.load('visualization', '1');
      function initialize() {
        var options = {
          center: new google.maps.LatLng(37.5,-122.23),
          zoom: 10,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map_canvas'), options);
        layer = new google.maps.FusionTablesLayer({
          query: {
            select: "'Delivery Zone'",
            from: tableid
          },
          map: map
        });
        window.onkeypress = enterSubmit;
      }
      function enterSubmit() {
        if(event.keyCode==13) {
          geocode();
        }
      }
      function geocode() {
        geocoder.geocode({address: document.getElementById('address').value }, findStore);
      }
      function findStore(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {        
          var coordinate = results[0].geometry.location;
          marker = new google.maps.Marker({
            map: map,
            layer: layer,
            animation: google.maps.Animation.DROP,
            position: coordinate
          });
          var queryText = encodeURIComponent("SELECT 'Store Name' FROM " + tableid +
              " WHERE ST_INTERSECTS('Delivery Zone', CIRCLE(LATLNG(" +
              coordinate.lat() + "," + coordinate.lng() + "), 0.001))");
          var query = new google.visualization.Query(
              'http://www.google.com/fusiontables/gvizdata?tq=' + queryText);
          query.send(showStoreName);
        }
      }
      function showStoreName(response) {
        if(response.getDataTable().getNumberOfRows()) {
          var name = response.getDataTable().getValue(0, 0);
          alert('Store name: ' + name);
        }
      }
    </script>
  </head>
  <body onload="initialize()">
    <input type="text" value="Palo Alto, CA" id="address">
    <input type="button" onclick="geocode()" value="Go">
    <div id="map_canvas" style="width:940; height:800"></div>
  </body>
</html>

请注意,如果圆与2个多边形相交,则可能会得到2个结果,或者可能会得到误报,因为半径不是0。