Error when adding HTML to google site, Google Maps

2019-08-31 04:20发布

问题:

I used the Fusion TablesLayer Wizard to layer three separate fusion tables and put it on my google site HERE. I copied and pasted the HTML code from the wizard into an HTML box on my site. But in the HTML Properties window it gives me this error: 12+9 - 58: failed to load external url js?sensor=false- I also tested this html in W3 schools 'TryIt' and it works fine. How do I get it to work on the site?

<!DOCTYPE html>
<html>
  <head>
  <style>
#map-canvas { width:900px; height:900px; }
.layer-wizard-search-label { font-family: sans-serif };
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
  var map;
var layer_0;
var layer_1;
var layer_2;
function initialize() {
  map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: new google.maps.LatLng(39.34723863007487, -100.37501562500003),
    zoom: 4,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  layer_0 = new google.maps.FusionTablesLayer({
    query: {
      select: "col2",
      from: "1qYb8PKCG3P7plw8aFVVpn44RgQI0CNaIuOFhs9RV"
    },
    map: map,
    styleId: 2,
    templateId: 3
  });
  layer_1 = new google.maps.FusionTablesLayer({
    query: {
      select: "col2",
      from: "11PndImUQQPvqjGiNKx87MRrTe71sLHnkGxo9bacC"
    },
    map: map,
    styleId: 2,
    templateId: 3
  });
  layer_2 = new google.maps.FusionTablesLayer({
    query: {
      select: "col2",
      from: "12bzY7A88cndb6bFS43jXSbYqt1AUPNbprYOGgJxj"
    },
    map: map,
    styleId: 2,
    templateId: 3
  });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
  </html>

回答1:

Do you need to include your API key? I've never really tried, but I don't think Google Maps lets you make anonymous calls. Here's the script from the documentation:

<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=SET_TO_TRUE_OR_FALSE">
</script>