簡體   English   中英

Google地圖加載失敗

[英]Google map failed to load

我需要將google map集成到我的網頁中。 我生成了一個API。 但是地圖沒有顯示。 我正在本地服務器上對其進行測試。

<h3>My Google Maps Demo</h3>
<div id="map">
    <span class="labels">Heading</span>
</div>
<script  src="https://maps.googleapis.com/maps/api/js?key=[API]&callback=initMap">
</script>
<script type="text/javascript">
    function initMap() {
                alert("Yes");
                var uluru = { lat: -25.363, lng: 131.044 };
                var map = new google.maps.Map(document.getElementById('map'), {
                    zoom: 4,
                    center: uluru
                });
                var marker = new google.maps.Marker({
                    position: uluru,
                    map: map
                });
            }
</script>

但沒有用。 他們在我的代碼中有問題嗎? 我可以檢查我的API是否正常工作

我無法發表評論,所以我在這里寫。 你有密碼嗎?

在控制台中,存在錯誤:

RefererNotAllowedMapError錯誤
當前加載Google Maps JavaScript API的網址尚未添加到允許的引薦來源網址列表中。 請在Google API控制台上檢查API密鑰的引薦來源網址設置。

請參閱Google API控制台中的API密鑰。 有關更多信息,請參閱安全使用API​​密鑰的最佳做法。

也許會對您有所幫助。

您需要具有api鍵才能訪問地圖。 像這樣修改您的代碼:

JS:

 function initMap() {
   alert("Yes");
   var uluru = {
     lat: -25.363,
     lng: 131.044
   };
   var map = new google.maps.Map(document.getElementById('map'), {
     zoom: 4,
     center: uluru
   });
   var marker = new google.maps.Marker({
     position: uluru,
     map: map
   });

 }
 google.maps.event.addDomListener(window, "load", initMap);

檢查此演示: http : //jsfiddle.net/lotusgodkk/hLenqzmy/64/

您可以從此處獲取api密鑰: https : //developers.google.com/maps/documentation/javascript/get-api-key

您的代碼運行正常。 您需要在其中放置一個JavaScript Google API(我想您在其中放置了另一個Google Maps Key)

在此處輸入圖片說明

還請查看鏈接以獲取一些Google示例

另外,將在頁面加載時調用initMap,並且在調用該頁面時尚未聲明MIGHT嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM