开发者

Why isn't this google maps loaded?

开发者 https://www.devze.com 2023-03-14 00:07 出处:网络
This is my code : <script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=true\"></script>

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 GBrowserIsCompatib开发者_JAVA百科le() it works, but it doesn't recognize the location.


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"
}); 


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> 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号