2017-05-20 49 views
0

我在我的索引頁有一個谷歌地圖,它工作。我現在檢查了它,它不再工作。代碼有問題嗎?谷歌HTML地圖上的地圖不再有效

<!-- Set height and width with CSS --> 
<div id="googleMap" style="height:600px;width:100%;"></div> 

<!-- Add Google Maps --> 
<script src="http://maps.googleapis.com/maps/api/js"></script> 
<script> 
var myCenter = new google.maps.LatLng(41.878114, -87.629798); 

function initialize() { 
var mapProp = { 
center:myCenter, 
zoom:12, 
scrollwheel:false, 
draggable:true, 
mapTypeId:google.maps.MapTypeId.ROADMAP 
}; 

var map = new google.maps.Map(document.getElementById("googleMap"),mapProp); 

var marker = new google.maps.Marker({ 
position:myCenter, 
}); 

marker.setMap(map); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 
</script> 

回答

0

如果您的項目是在服務器上運行,那麼它需要api鍵,如果脫機應該工作。

加載谷歌地圖的JavaScript API

要加載谷歌地圖的JavaScript API,使用腳本標記像在下面的例子:

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&callback=myMap"></script> 

The URL contained in the script tag is the location of a JavaScript file that loads all of the symbols and definitions you need for using the Maps 

的JavaScript API。此腳本標記是必需的。

異步屬性可讓瀏覽器在加載Maps JavaScript API時呈現網站的其餘部分。當API準備就緒時,它將調用使用callback參數指定的函數。

關鍵參數包含您的應用程序的API密鑰。請參閱獲取更多信息。

注意:在加載API時,Google Maps API Premium Plan客戶可能使用API​​密鑰或有效的客戶端ID。獲取更多關於Premium Plan客戶認證參數的信息。