Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map doesn't get displayed Google Maps API V3

Code with V3 API.

function initialize ()
{
    if (GBrowserIsCompatible()) 
    { 
        var ch = new GLatLng (0,0);

        var myOptions = {
            zoom:7,
            center: ch,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }

        map = new google.maps.Map(document.getElementById("map"), myOptions);

        directionsDisplay = new google.maps.DirectionsRenderer(map, document.getElementById("map"));
        directionsDisplay.setMap(map);                  
    }
}

Code with V2 API.

function initialize ()
{
     if (GBrowserIsCompatible()) 
     { 
         map = new GMap2 (document.getElementById("map"));
         map.setCenter (new GLatLng(0,0),1 );
     }
}

The V2 API code worked flawlessly, the V3 API code is NOt displaying any map. What's the point that I am missing?

EDIT Modified the V3 code as follows, but still no maps:

var chicago = new google.maps.LatLng (0, 0);

var myOptions = {
    zoom:1,
    center: chicago,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}

map = new google.maps.Map(document.getElementById("map"), myOptions);
like image 491
Aquarius_Girl Avatar asked May 30 '11 13:05

Aquarius_Girl


2 Answers

Make sure you are loading the correct Google Maps API, that you have a div tag with an id of map, and (for good measure) that you give the div a height and width. (Perhaps better to put the height and width in a stylesheet, but for clarity, I'm including it inline here.)

Here's a web page with your post-edit code. Try it. Works for me.

<html>
<head>
<title>Google Map test</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body>
<div id="map" style="height:500px;width:500px"></div>
<script>
var chicago = new google.maps.LatLng (0, 0);

var myOptions = {
    zoom:1,
    center: chicago,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}

map = new google.maps.Map(document.getElementById("map"), myOptions);
</script>
</body>
</html>
like image 199
Trott Avatar answered Oct 04 '22 07:10

Trott


In V3, all the names have changed. For example, GLatLng is now google.maps.LatLng. You will need to revise your code to use the new names.

A link to the docs in case you don't have it

like image 33
Ray Avatar answered Oct 04 '22 06:10

Ray