我使用FusionTablesLayer和Google Maps JavaScript API v3时的空白页面

时间:2012-10-08 20:28:50

标签: google-maps-api-3 google-fusion-tables

我使用融合表的数据准备了一个简单的页面。 (FusionTablesLayer使用Google Maps JavaScript API v3)但不显示地图。您可以在此处查看页面:http://www.siterary.com/0test.html。有什么问题 ?代码如下

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>test</title>
    <link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
    <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBK_ErFIm-CYBsslK_9ZB6m0wPV197UaJg&sensor=false"></script>
    <script>

      function initialize() {

        var  istanbul = new google.maps.LatLng(41.01, 28.97);

        map = new google.maps.Map(document.getElementById('map_canvas'), {
          center: istanbul,
          zoom: 11,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        layer = new google.maps.FusionTablesLayer({
          query: { 
            select:  'Location' ,
            from: '1s3DYRvmNAfKgo-swjG39-8UEb9tHMm0UPHvW_tc'
          }
        });
        layer.setMap(map);
      }
    </script>
  </head>
  <body onload="initialize()">

<B>MAP</B> <BR>

    <div id="map_canvas"></div>
  </body>
</html>

1 个答案:

答案 0 :(得分:2)

您网站上不存在“/maps/documentation/javascript/examples/default.css”文件。您的地图没有有效的尺寸。

Working version

代码段

function initialize() {

  var istanbul = new google.maps.LatLng(41.01, 28.97);

  map = new google.maps.Map(document.getElementById('map_canvas'), {
    center: istanbul,
    zoom: 11,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  layer = new google.maps.FusionTablesLayer({
    query: {
      select: 'Location',
      from: '1s3DYRvmNAfKgo-swjG39-8UEb9tHMm0UPHvW_tc'
    }
  });
  layer.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
#map_canvas {
  height: 100%;
}
@media print {
  html,
  body {
    height: auto;
  }
  #map_canvas {
    height: 650px;
  }
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<B>MAP</B> 
<BR>

<div id="map_canvas"></div>