2013-02-22 98 views
11

標記沒有顯示出來,我閱讀了文檔,但我找不到問題,有人可以幫我查詢嗎?谷歌地圖標記沒有顯示API v3

繼承人的JS:

function initialize() { 
     var mapOptions = { 
     center: new google.maps.LatLng(-8.064903, -34.896872), 
     zoom: 16, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
     var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 

     var marker = new google.maps.Marker({ 
      position: location, 
      title:"Hello World!", 
      visible: true 
     }); 
     marker.setMap(map); 
    } 
+3

什麼是「位置」? – alestanis 2013-02-22 14:31:36

回答

22

我的猜測是,你location對象沒有定義。嘗試將您的標記位置設置爲與地圖中心相同的LatLng,然後查看它是否有效:

function initialize() { 
    latLng = new google.maps.LatLng(-8.064903, -34.896872) 
    var mapOptions = { 
    center: latLng, 
    zoom: 16, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 

    var marker = new google.maps.Marker({ 
     position: latLng, 
     title:"Hello World!", 
     visible: true 
    }); 
    marker.setMap(map); 
} 
+0

我剛剛創建了var location = new google.maps.LatLng(-8.064903,-34.896872);它的工作!謝謝! – 2013-02-22 14:35:51

+1

@RamonVasconcelos太好了!不要忘記接受答案,如果它解決了你的問題,並與GMaps祝你好運! – alestanis 2013-02-22 15:04:50