首页 > 解决方案 > (Google Map API) 地理编码不成功,原因如下:REQUEST_DENIED

问题描述

我是这个地方的新手,我迫切需要这里专家的帮助!D=

我试图制作一个可以生成动态数字谷歌地图的页面。但是,该网页继续显示Geocode was not successful for the following reason: REQUEST_DENIED

我再次检查了我的 google API 控制台并确认地理编码 API 和 Javascript API 已启用。(我确实启用了列表中的所有 Google 地图 API……)

我的 Google Map API 列表

有人可以看看并告诉我为什么吗?T_T

//------------------------------------------------ \\

下面是我的 javascript 和 html 按钮:

Javascript:

    <script async defer src="https://maps.googleapis.com/maps/api/js?key=APIkey&callback=initMap"
    type="text/javascript"></script>

    <script async defer src="https://maps.googleapis.com/maps/api/js?key=APIKEY&callback=mapAddress"
    type="text/javascript"></script>
    <!-- &callback=mapAddress -->

        <script>
        function mapAddress(mapElement, address) {
        var geocoder = new google.maps.Geocoder();
        // alert(mapElement);
        // alert(address);
        geocoder.geocode({ 'address': address }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var mapOptions = {
                    zoom: 17,
                    center: results[0].geometry.location,
                    disableDefaultUI: true
                };
                var map = new google.maps.Map(document.getElementById(mapElement), mapOptions);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
        }
        </script>

HTML(应该是 php 变量):

<button type="button" class="button_mapAPI" id="address_<?php echo $case["id"]; ?>"  value="<?= $case['location_detail'] ?>" onclick="mapAddress('map1', 'Hong Kong')"/>Map Refresh</button>

标签: javascripthtmlgoogle-mapsbutton

解决方案


您是否启用了 API 密钥计费?谷歌地图不再免费。您必须关联一张信用卡,这样如果您的网站的请求超过了他们每月免费提供给您的 200 美元信用额度,您就可以收到账单。


推荐阅读