Larry
Larry

Reputation: 461

Google maps example not working

I'm trying to run a simple google maps example (this is the example: https://developers.google.com/maps/documentation/javascript/examples/map-simple-async). I put the code in my .hmtl file but I`m getting a blank page. And, of course this seems to happen with all google examples (I save all my files on ANSI format).

The code is:

<!DOCTYPE html> <html>   <head>

<title>Asynchronous Loading</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<script>
    function initialize()
    {
        var mapOptions = {
            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'), mapOptions);
    }

    function loadScript()
    {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = 'http://maps.googleapis.com/maps/api/js?key=<MY_CODE>&sensor=false&callback=initialize';
        document.body.appendChild(script);
    }

    window.onload = loadScript;

</script>   </head>   <body>
<div id="map-canvas"></div>   </body> </html>

Upvotes: 0

Views: 2007

Answers (1)

duncan
duncan

Reputation: 31912

On that Google example they also include a link to a CSS file. You don't have any CSS (either inline or external) in the code you've put into the answer.

Look at their CSS file, you'll need something similar:

https://developers.google.com/maps/documentation/javascript/examples/default.css

Upvotes: 1

Related Questions