markzzz
markzzz

Reputation: 47947

Why isn't this google maps loaded?

This is my code :

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>     
<script type="text/javascript">
    function load() {
        if (GBrowserIsCompatible()) {
            var map;
            var location = new google.maps.LatLng(46.084989, 11.118851);

            var stylez =
            [
              {
                  featureType: "all",
                  elementType: "all",
                  stylers: [
                  { saturation: -98 }
                ]
              }
            ];

            var mapOptions = {
                zoom: 11,
                center: location,
                mapTypeControlOptions: {
                    mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'myScale']
                }
            };

            map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
            var mapType = new google.maps.StyledMapType(stylez, { name: "Grayscale" });
            map.mapTypes.set('myScale', mapType);
            map.setMapTypeId('myScale')        
        }
    }

    $(document).ready(function(){
        load();
    });
</script>


<div id="map_canvas" style="width: 100%; height: 700px"></div>

but nothing is loaded. Where am I wrong? Removing GBrowserIsCompatible() it works, but it doesn't recognize the location.

Upvotes: 0

Views: 413

Answers (2)

Alex
Alex

Reputation: 249

Map API V2 is deprecated use V3. If you remove GBrowserIsCompatible() it will work and the map will be centered at your desired coordinates.

To highlight better the location you could use a marker

var marker = new google.maps.Marker({
    position: location,
    map: map,
    title:"My location title"
}); 

Upvotes: 2

Wicked Coder
Wicked Coder

Reputation: 1118

I think you are trying to use Gmaps API V3 and GBrowserIsCompatible() is not supported with that version. In order to use this functionality you need to use API V2.

<script src="http://maps.google.com/mapsfile=api&amp;v=2&amp;key=abcdefg&sensor=true" type="text/javascript"></script> 

Upvotes: 2

Related Questions