Lingfeng Xiong
Lingfeng Xiong

Reputation: 1171

Google Map not shown

I write a web page, and inserted Google Map into it. But the map always not shown. I tried to use Firebug to see what happened, and found there are no errors.

The div of map-canvas has been correctly replaced by Google Map API but that div not shown... I debugged this for several days, still no solution.

    <html><head>
        <meta charset="UTF-8">
        <meta content="IE=Edge" http-equiv="X-UA-Compatible">

        <meta content="initial-scale=1.0, user-scalable=no" name="viewport">
        <meta charset="utf-8">

        <title>TaskPaneApp1</title>
        <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js" style=""></script>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    </head>

    <body>
        <!-- Page content -->
        <div id="content-header">
            <div class="padding">
                <h1>Welcome</h1>
            </div>
        </div>
        <div id="content-main">
            <div class="padding">
                <p><strong>Add home screen content here.</strong></p>
                <p>For example:</p>
                <button id="get-data-from-selection">Get data from selection</button>

                <p style="margin-top: 50px;">
                    <a href="http://go.microsoft.com/fwlink/?LinkId=276812" target="_blank">
                        Find more samples online...
                    </a>
                </p>
                <div style="position: relative">
                    <p>Hey there!</p>
                    <div style="position: relative; width: 100%; height: 500px">
                        <div id="map-canvas">
                            Loading...
                        </div>
                    </div>  
                    <p>This is the end of the map</p>
                </div>
            </div>
        </div>

    <script type="text/javascript">
        var map;
            function initialize() {
              var mapOptions = {
                zoom: 8,
                center: new google.maps.LatLng(-34.397, 150.644),
                mapTypeId: google.maps.MapTypeId.ROADMAP
              };
              map = new google.maps.Map(document.getElementById('map-canvas'),
                  mapOptions);
            }

            google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    </body></html>

Upvotes: 1

Views: 297

Answers (2)

geocodezip
geocodezip

Reputation: 161324

Your map div doesn't have a size. This:

<div id="map-canvas" style="height:300px; width:300px;"> 

makes it display for me.

Upvotes: 1

Sean Henderson
Sean Henderson

Reputation: 596

You didn't set the dimensions of the map div, but of the div that the map is nested in. Add height and width properties to div id 'map-canvas' and the map should appear.

    <div id="map-canvas" style="width: 400px; height: 400px;">Loading...</div>

Upvotes: 2

Related Questions