简体   繁体   English

Google地图加载失败

[英]Google map failed to load

I need to integrate a google map in my web page. 我需要将google map集成到我的网页中。 I generated a API. 我生成了一个API。 But the map is not displaying. 但是地图没有显示。 I am testing it in my local server. 我正在本地服务器上对其进行测试。

<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>

but no use. 但没有用。 Is their any issue in my code? 他们在我的代码中有问题吗? Can i check my API is working or not 我可以检查我的API是否正常工作

I cannot comment, so I write here. 我无法发表评论,所以我在这里写。 Do you have key code? 你有密码吗?

In console, there are errors: 在控制台中,存在错误:

RefererNotAllowedMapError Error RefererNotAllowedMapError错误
The current URL loading the Google Maps JavaScript API has not been added to the list of allowed referrers. 当前加载Google Maps JavaScript API的网址尚未添加到允许的引荐来源网址列表中。 Please check the referrer settings of your API key on the Google API Console. 请在Google API控制台上检查API密钥的引荐来源网址设置。

See API keys in the Google API Console. 请参阅Google API控制台中的API密钥。 For more information, see best practices for securely using API keys. 有关更多信息,请参阅安全使用API​​密钥的最佳做法。

Maybe this would help you. 也许会对您有所帮助。

You need to have api key to access the maps. 您需要具有api键才能访问地图。 Modify your code like this: 像这样修改您的代码:

JS: 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);

Check this demo: http://jsfiddle.net/lotusgodkk/hLenqzmy/64/ 检查此演示: http : //jsfiddle.net/lotusgodkk/hLenqzmy/64/

You can get the api key from here: https://developers.google.com/maps/documentation/javascript/get-api-key 您可以从此处获取api密钥: https : //developers.google.com/maps/documentation/javascript/get-api-key

Your code is working fine. 您的代码运行正常。 You need to place a JavaScript Google API there (I guess you placed another Google Maps Key) 您需要在其中放置一个JavaScript Google API(我想您在其中放置了另一个Google Maps Key)

在此处输入图片说明

Also check out this link for some google examples 还请查看链接以获取一些Google示例

另外,将在页面加载时调用initMap,并且在调用该页面时尚未声明MIGHT吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM