2011-06-20 32 views
0

這是我的代碼:爲什麼不是這個谷歌地圖加載?

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

,但沒有被加載。我錯在哪裏?刪除GBrowserIsCompatible()它可以工作,但它不能識別位置。

+0

這是所有的代碼?因爲你正在嘗試使用jQuery函數,並且我沒有看到加載的jQuery庫 – eveevans

回答

2

地圖API V2已棄用使用V3。如果刪除GBrowserIsCompatible(),它將起作用,地圖將會以您想要的座標爲中心。

爲了更好地突出的位置,你可以使用一個標記

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

我認爲你要使用Gmaps API V3和GBrowserIsCompatible()未與該版本支持。爲了使用此功能,您需要使用API​​ V2。

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