【问题标题】:Google Maps API error: Google Maps API error: RefererNotAllowedMapError [duplicate]Google Maps API 错误:Google Maps API 错误:RefererNotAllowedMapError [重复]
【发布时间】:2016-08-02 08:12:24
【问题描述】:

我正在关注 Google Maps API 的教程,我得到了 API 的代码,但它仍然没有显示地图

我收到此错误:

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

Header.php

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

<body   onload="initialize">

ma​​p.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>

【问题讨论】:

    标签: google-maps google-maps-api-3


    【解决方案1】:

    我看不出您的代码无法正常工作的任何明确原因。

    唯一的原因可能是,如果您的 API 密钥是使用您的域名注册的,它将不允许在开发环境/本地主机中使用任何 Google 地图元素。

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

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

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

    所以您的非 https 网站脚本将是

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

    如果您在实时实例中遇到此问题,请确保该脚本和您的域都使用相同的协议,即httphttps。不要混合组合。

    进一步的建议:给logo.png一个更合格的名字

    你应该已经启动并运行了。

    【讨论】:

      猜你喜欢
      • 2016-06-01
      • 2017-04-26
      • 1970-01-01
      • 2018-04-26
      • 2016-10-26
      • 2021-09-28
      • 2016-09-16
      • 2020-09-06
      • 2012-10-12
      相关资源
      最近更新 更多