[英]markercluster and google maps v3 error “a is undefined”
[英]Google Maps v3, error message “Google is undefined”
我正在嘗試實現基本的“Hello world”應用程序而在我的網站上收到錯誤:
<div id="map"></div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
$(document).ready(function () {
map = new google.maps.Map(document.getElementById("map"), myOptions);
});
我得到的錯誤是:
'未捕獲的ReferenceError:未定義谷歌'
我該如何解決這個問題?
您的來源有誤,我還建議您指定要加載的確切版本:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&sensor=true"></script>
這應該有所幫助。
如果您的主站點位於https平台且地圖位於http,則有時會在瀏覽器Google Chrome中發生這種情況。 為了顯示地圖,你在URL框中有一個盾牌,只需點擊盾牌就可以顯示它。
您的代碼中有很多東西:
你已經給了document.ready
但是沒有jQuery
鏈接
您的document.ready
必須位於<script>
標記</script>
您還應該為您持有地圖的div
指定height
和width
,因此它只是一個空標記。
您已經為Map定義了myOptions,並且沒有任何內容可以解釋為map在加載地圖時需要考慮的選項**
這是一個完整的例子:
<html>
<body>
<div id="map" style="width:500px;height:500px;"></div>
<script type="text/javascript" src="Please put your jquery here"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var myLatlng = new google.maps.LatLng(40.65, -73.95);
var myOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$("document").ready(function () {
map = new google.maps.Map(document.getElementById("map"), myOptions);
});
</script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.