65896

Why is my Google Maps “Hello world?” page displaying as empty?

Question:

I have the source of my page below; I tried to load Google Maps into Boilerplate 3, and am getting a blank page with no JavaScript errors. How could this be improved?

<!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title></title> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="css/style.css"> <script src="js/libs/modernizr-2.5.3.min.js"></script> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100%, width: 100% } </style> </head> <body> <!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.

<![endif]--> <header> </header> <div role="main"> <div id="map_canvas"> </div> </div> <footer> </footer> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script> <script src="js/plugins.js"></script> <script src="js/script.js"></script> <script> function initialize() { var myoptions = { zoom: 4, center: new google.maps.LatLng(42.881944, -87.627778), mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map_canvas'), myoptions); } function load_script() { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://maps.google.com/maps/api/js?key=AIzaSyAi288X8h9Y4fXM21Q0-my6O6kiLaDeC7M&sensor=false&callback=initialize"; document.body.appendChild(script); } window.onload = load_script; </script> </body> </html>

--EDIT--

The code I cobbled together from Google's example first started on painting a map, then wiped the screen and said my key couldn't used for it:

<!DOCTYPE html> <html> <head> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAi288X8h9Y4fXM21Q0-my6O6kiLaDeC7M&sensor=true"> </script> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> </head> <body onload="initialize();"> <script> function initialize() { var myOptions = { zoom: 8, center: new google.maps.LatLng(-34.397, 150.644), mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } function loadScript() { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=false&callback=initialize"; document.body.appendChild(script); } window.onload = loadScript; </script> <body> <div id="map_canvas" style="width: 100%; height: 100%"></div> </body> </html>

Answer1:

Define a width for the map_canvas div.

Recommend

  • Css filter blur is not working in Cordova app, Android 4.4.2, Nexus 4
  • Detecting canvas text API support (Opera Mini)
  • Back button breaks page in Chrome
  • Detecting Windows Tablet (touch windows devices) with Jquery
  • python function to set accuracy of float
  • Easy Way to Get Averages Based on Names in List
  • Apply a gradle plugin with a common configuration to all projects
  • maven-dependency-plugin ignores outputDirectory configuration
  • SCons libraries and sub-libraries
  • object play not found in scala application
  • How do I obtain a list of files that changed from svn over a date range?
  • Embedding a Google map
  • integrate POCO library in android ndk
  • blade.php method outputting it's result to the form
  • Uncaught TypeError: $(…).select2 is not a function
  • Simulate click Geckofx vb,net
  • How to view images from protected folder with php?
  • Adjust width of select element according to selected option's width
  • Display images in Django
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Sencha Touch 2.0 Controller refs attribute not working?
  • How do I alternate colors in Flat List (React Native)
  • Listbox within Listbox and scrolling trouble in Windows Phone 7 Silverlight
  • Jquery UI tool tip close icon
  • DomPDF {PAGE_NUM} not on first page
  • Javascript simulate pressing enter in input box
  • HTML download movie download link
  • Resize panoramic image to fixed size
  • Modifying destination and filename of gulp-svg-sprite
  • How to show dropdown in excel using jrxml (jasper api)?
  • Importing jscolor library in angular 2
  • jquery mobile loadPage not working
  • align graphs with different xlab
  • Unanticipated behavior
  • A cron job substitute?
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Change div Background jquery
  • python draw pie shapes with colour filled