[英](Google Map API) Geocode was not successful for the following reason: REQUEST_DENIED
我是这个地方的新手,我迫切需要这里专家的帮助! D=
我试图制作一个可以生成google map动态数字的页面。 但是,网页一直显示Geocode was not successful for the following reason: REQUEST_DENIED
。
我仔细检查了我的谷歌 API 控制台并确认地理编码 API 和 Javascript ZDB974238714CA8DE634A7CE1D 已启用。 (我确实启用了列表中的所有 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>
您是否启用了 API 密钥的计费? 谷歌地图不再免费。 您必须关联一张信用卡,这样如果您的网站的请求超过了他们每月免费提供给您的 200 美元信用额度,您就可以收到账单。
首先,问题是异步加载脚本,删除它..
用你的 API KEY 试试那个 jsfiddle
(function(){ let mapElement = 'map'; let address = 'SPAIN'; geocoder = new google.maps.Geocoder(); 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); } }); })();
#map { width: 100%; height: 350px; }
<script src="https://maps.googleapis.com/maps/api/js?key=APIKEY" type="text/javascript"></script> <div id="map"></div>
需要启用将地址转换为坐标的地理编码 api,它有点贵,使用坐标而不是地址,不需要地理编码 API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.