简体   繁体   中英

Google Maps Places API Map not showing up

I just started working with the google maps places API and have been able to pull together this code but the map doesn't show up. I would imagine it is a small error somewhere but I can't find it. If anyone could point it out that would be a huge help and also is there anywhere online or any free IDEs that are good for catching errors like this?

Code: http://jsbin.com/ifuwel/1/edit

You have 2 different IDs ("map" and "map_canvas"). Try that:

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

Try this basic example

HTML

 <body onload="initialize()">
   <div id="map_canvas"></div>
 </body>

Javascript

    <script>
  function initialize() {
    var mapOptions = {
      zoom: 4,
      center: new google.maps.LatLng(-33, 151),
      panControl: false,
      zoomControl: false,
      scaleControl: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById('map_canvas'),
                                  mapOptions);
  }
</script>

CSS

    <style>
     html, body {
     height: 100%;
     margin: 0;
     padding: 0;
      }

     #map_canvas {
     height: 100%;
     }

     @media print {
     html, body {
     height: auto;
     }

     #map_canvas {
     height: 650px;
     }
      }
    </style>

CSS help to have 100% of the width and height if desired

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM