首页 > 解决方案 > 地理编码不成功,原因如下:Google Map Integration 中的 REQUEST_DENIED

问题描述

我们已经在我们的 wordpress 网站中集成了谷歌位置图,但是现在当我加载该页面时它显示错误

地理编码不成功,原因如下:REQUEST_DENIED

当地图显示褪色地图时,仅用于开发目的。我的代码如下所示。

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>
    <script type="text/javascript">         var geocoder, map;      function mapInit(address) {             geocoder = new google.maps.Geocoder();          var latlng = new google.maps.LatLng(-34.397, 150.644);          var mapOptions = {
                zoom: 8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP            }           map = new google.maps.Map(document.getElementById('map'), mapOptions);          codeAddress(address);       }       function codeAddress(address) {             geocoder.geocode( { 'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });
                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }           });         }       $(function(){           mapInit($('.current-contact .address b').html());
                        $('.location').click(function() {
                var $this = $(this),
                    currentAddr = $('.current-contact').html(),
                    nextAddr = $this.html(),
                    address = $this.find('.address b').html();

                codeAddress(address);
                $('.current-contact').html(nextAddr);
                //$this.html(currentAddr);          });         });
    </script>

当我获得 api 代码时,我需要在这个脚本中进行哪些更改?

标签: wordpressgoogle-mapsgoogle-apigeolocation

解决方案


推荐阅读