Fusion Tables搜索和缩放

时间:2014-03-31 09:03:08

标签: google-maps google-fusion-tables

感觉我正在失去理智,因为我不知道我错过了什么。我正在尝试复制https://developers.google.com/fusiontables/docs/samples/search_and_zoom中使用的示例,与该表格上的表格完全相同,用于Fusion Table ID 1IYJMddMoWgwjieq3rwh8YyiHVpZy_1--hoNrPPa2

给出的代码是:

<!DOCTYPE html>
<!--
  Copyright 2011 Google Inc. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
 <html>
   <head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">

<title>Fusion Tables Layer Example: Search and Zoom</title>

<link href="/apis/fusiontables/docs/samples/style/default.css"
    rel="stylesheet" type="text/css">
<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=false"></script>

<script type="text/javascript">

  function initialize() {
    var defaultCenter = new google.maps.LatLng(10, 10);
    var defaultZoom = 2;
    var tableId = '1ZU8D1ASYZMeIise2gboBt-HPt9hX8Y2NIdMfZg';
    var locationColumn = 'lat';
    var geocoder = new google.maps.Geocoder();

    var map = new google.maps.Map(document.getElementById('map-canvas'), {
      center: defaultCenter,
      zoom: defaultZoom,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var layer = new google.maps.FusionTablesLayer({
      query: {
        select: locationColumn,
        from: tableId
      },
      map: map
    });

    var zoomToAddress = function() {
      var address = document.getElementById('address').value;
      geocoder.geocode({
        address: address
      }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
          map.setZoom(10);

          // OPTIONAL: run spatial query to find results within bounds.
          var sw = map.getBounds().getSouthWest();
          var ne = map.getBounds().getNorthEast();
          var where = 'ST_INTERSECTS(' + locationColumn +
              ', RECTANGLE(LATLNG' + sw + ', LATLNG' + ne + '))';
          layer.setOptions({
            query: {
              select: locationColumn,
              from: tableId,
              where: where
            }
          });
        } else {
          window.alert('Address could not be geocoded: ' + status);
        }
      });
    };

    google.maps.event.addDomListener(document.getElementById('search'),
             'click', zoomToAddress);
         google.maps.event.addDomListener(window, 'keypress', function(e) {
           if (e.keyCode == 13) {
             zoomToAddress();
           }
         });
         google.maps.event.addDomListener(document.getElementById('reset'),
             'click', function() {
               map.setCenter(defaultCenter);
               map.setZoom(defaultZoom);
               layer.setOptions({
                 query: {
                   select: locationColumn,
                   from: tableId
                 }
               });
             });
       }

       google.maps.event.addDomListener(window, 'load', initialize);

     </script>
   </head>
   <body>
     <div id="map-canvas"></div>
     <div>
       <label>Enter an address:</label>
       <input type="text" id="address" value="Mountain View, CA">
       <input type="button" id="search" value="Search!">
       <input type="button" id="reset" value="Reset">
     </div>
   </body>
 </html>

我真的只是替换了:

 var defaultCenter = new google.maps.LatLng(10, 10);
 var defaultZoom = 2;
 var tableId = '1ZU8D1ASYZMeIise2gboBt-HPt9hX8Y2NIdMfZg';
 var locationColumn = 'lat';

使用:

 var defaultCenter = new google.maps.LatLng(-33.927758210970154, 150.95845901699215);
 var defaultZoom = 10;
 var tableId = '1IYJMddMoWgwjieq3rwh8YyiHVpZy_1--hoNrPPa2';
 var locationColumn = 'col3';

我认为它会起作用,但地图本身不会显示。然后我想我会使用示例代码并测试它而不更改它但它也不会工作。

我错过了什么?!完全不知道我做错了什么。

1 个答案:

答案 0 :(得分:0)

可能未加载包含的样式表(路径仅在文档位于google-developers.appspot.com时有效),因此#map-canvas没有高度。

通过https://google-developers.appspot.com/fusiontables/docs/samples/style/default.css

指定高度或加载样式表