2013-10-02 46 views
-1

我下面的谷歌地圖API,並添加以下代碼,但不顯示標記谷歌地圖標記不顯示爲什麼?

function initialize() { 
     var myLatlng = new google.maps.LatLng(27.7000, 85.3333); 
     var map_canvas = document.getElementById('map_canvas'); 
     var map_options = { 
      center: new google.maps.LatLng(27.7000, 85.3333), 
      zoom: 12, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     } 

     // To add the marker to the map, use the 'map' property 
     var marker = new google.maps.Marker({ 
      position: myLatlng, 
      map: map, 
      title:"Hello World!" 
     }); 
     // To add the marker to the map, call setMap(); 
     marker.setMap(map); 

     var map = new google.maps.Map(map_canvas, map_options) 
     } 
     google.maps.event.addDomListener(window, 'load', initialize); 
+0

你的HTML/css看起來像什麼?你的map_canvas div有多大?任何JavaScript錯誤? – geocodezip

+0

100%寬度和400px高度貼圖顯示,但不是標記 –

回答

0

您要添加的標記之後創建的地圖,所以在這一點上

var map = new google.maps.Map(map_canvas, map_options); 

    marker.setMap(map); 

你可能有一些JavaScript錯誤,所以看看控制檯日誌

+0

沒有錯誤顯示 –

+0

先創建貼圖,然後將標記附加到它 – KeepCalmAndCarryOn

+0

是的,我是在那個錯誤。 –