Google Maps API错误:Google Maps API错误:RefererNotAllowedMapError [英] Google Maps API error: Google Maps API error: RefererNotAllowedMapError

查看:1737
本文介绍了Google Maps API错误:Google Maps API错误:RefererNotAllowedMapError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注Google Maps API上的教程,并且获取了API代码,但仍未向我显示地图。



出现此错误:


Google Maps API错误:Google Maps API错误:
RefererNotAllowedMapError

Header.php

 < script type =text / javascriptsrc =https://maps.googleapis.com/maps/api/js?key=AIzaSyDLDV40Ut-yGLG9r4N629K8-Rv0dtQsZzQ>< / script> 

< body onload =initialize>

map.php

 < script type =text / javascript> 

函数initialize(){
var myLatLng = {lat:42.52501,lng:2.938979};
var map = new google.maps.Map(document.getElementById('map'),{
zoom:12,
center:myLatLng,
scrollwheel:false,
draggable:true,
});

var image ='logo.png';
var marker = new google.maps.Marker({
position:myLatLng,
map:map,
icon:image
});
}

< / script>


解决方案

我看不到任何明确的原因,不工作。

唯一的原因可能是您的API密钥注册了您的域名,它将不允许开发环境/ localhost中的任何Google Maps元素。



如果您在本地机器上运行此脚本,请从脚本中移除您的API密钥

 < script type =text / javascriptsrc =https://maps.googleapis.com/maps/api/js?>< / script> 

另外,在本地开发时使用 http 而不是 https 。尝试使用 http 更改Google Maps脚本的 src ,因为可能存在安全原因,因为您可能会得到此错误。



因此,非https网站的脚本将为

 < ; script type =text / javascriptsrc =http://maps.googleapis.com/maps/api/js?>< / script> 

如果您在实例中遇到此问题,请确保脚本和您的域都使用同样的协议是 http https 。不要混用这些组合。

进一步的建议:给 logo.png



您应该已开始运行。


I'm following a tutorial on the Google Maps API and I get the code of API but its still not showing me the map

I get this error :

Google Maps API error: Google Maps API error: RefererNotAllowedMapError

Header.php

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDLDV40Ut-yGLG9r4N629K8-Rv0dtQsZzQ"></script>

<body   onload="initialize">

map.php

<script type="text/javascript">

    function initialize() {
        var myLatLng = { lat: 42.52501, lng: 2.938979 };
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 12,
            center: myLatLng,
            scrollwheel: false,
            draggable: true,
        });

        var image = 'logo.png';
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            icon: image
        });
    }

</script>

解决方案

I could not see any clear reason why your code is not working.

The only reason can be if your API key is registered with your domain name it will not allow any Google Maps element in the development environment/localhost.

If you are running this on local machine remove your API key from the script

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?"></script>

Also, use http when developing on local machine rather than https. Try changing the Google Maps script's src with http as there might be a security reason due to which you might be getting this error.

So your script for non-https site will be

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?"></script>

If you are getting this problem in your live instance then make sure that script and your domain both use the same protocol which is either http or https. Do not mix the combinations.

Further suggestion: Give a more qualified name to the logo.png

You should be up and running.

这篇关于Google Maps API错误:Google Maps API错误:RefererNotAllowedMapError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆