Javascript代码未生成Google Map API

时间:2017-01-21 23:14:52

标签: javascript html google-maps google-maps-api-3 google-maps-markers

脚本不会渲染地图。



<!DOCTYPE html>
<html>
  <head>
    <style>
       #map-canvas {
        margin: 0;
        padding: 0;
        height: 400px;
        width: 100%;
       }
    </style>
  </head>
  <body>
    <h3>My Google Maps Demo</h3>
    <div style= "Height:100% Width:100%;">
      <div id ="map-canvas"></div></div>
    <script
    src="https://maps.googleapis.com/maps/api/js?key=API_Key&callback=initMap">
        //I am not sure what going on for some reason the map will not load and I am not sure if it is because of issues with my formatting or what, but I am lost. 
    </script>
    <script type ="text/javascript">
      function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 4,
          center: {lat: -27.3818611, lng: 152.7130136},
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });
         var places = [
                      {lat: -25.363, lng: 131.044, Name: "Uluru"},
                      {lat:-24.363, lng: 131.044, Name: "Placeland"}];
        var marker, i;
        var markers = new Array();
        for(var i=0; i<crimes.length; i++){
            var marker = new google.maps.Marker({
                      position: places[i].lat, places[i].lng, 
                      map: map,
                      title: places[i].Name
                //I am trying to get a marker with this but am not sure if the code is incorrect.
                      });
                      }
      }
        
                      
    </script>
    
  </body>
</html>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:3)

document.getElementById('map')应为document.getElementById('map-canvas')

答案 1 :(得分:1)

没关系我修好了。

formatted: Error: Invalid CSS after "...a-breakpoint-up": expected "{", was "(lg) {"

问题在于没有关闭括号等。