2012-02-08 24 views
3

我正在使用Google Maps,並且想要將地圖加載到外部文件中,我可以使用jQuery來設置頁面的其餘部分。JavaScript:在外部腳本中初始化Google地圖

我已經進行了三次更改Hello World example:我已經包括jQuery的,我一直在初始化一個外部文件中的地圖,我已經移除了<body>標籤onload事件。我現在有一個空白的屏幕,以前有一個地圖,並沒有控制檯的錯誤給我一個線索。

這是我的HTML:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
    <style type="text/css"> 
     html { height: 100% } 
     body { height: 100%; margin: 0; padding: 0 } 
     #map_canvas { height: 100% } 
    </style> 
    <script src="./js/jquery.js"></script> 
    <script type="text/javascript" 
     src="http://maps.googleapis.com/maps/api/js?sensor=true"> 
    <script src="./js/maps.js"></script> 
    </head> 
    <body> 
    <div id="map_canvas" style="width:100%; height:100%"></div> 
    </body> 
</html> 

這是maps.js全:

$(document).ready(function() { 
    console.log('document ready'); 
    function initializeMap() { 
    console.log('initialize'); 
    var myOptions = { 
     center: new google.maps.LatLng(-34.397, 150.644), 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     myOptions); 
    } 
    initializeMap(); 
}); 

我沒有看到任何控制檯語句。我也看不到地圖 - 只是一個空白的屏幕。

我一定在做一些愚蠢的事情,但它是什麼?

回答

3

你錯過了一個</script>src="http://maps.googleapis.com/maps/api/js?sensor=true">

+0

謝謝!驚訝沒有控制檯錯誤:( – Richard 2012-02-08 18:10:23