javascript - (Google Map API) 地理编码不成功,原因如下:REQUEST_DENIED
问题描述
我是这个地方的新手,我迫切需要这里专家的帮助!D=
我试图制作一个可以生成动态数字谷歌地图的页面。但是,该网页继续显示Geocode was not successful for the following reason: REQUEST_DENIED
。
我再次检查了我的 google API 控制台并确认地理编码 API 和 Javascript API 已启用。(我确实启用了列表中的所有 Google 地图 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 美元信用额度,您就可以收到账单。
推荐阅读
- loopback4 - Loopback 4 - 未记录的模型属性
- swift - 在swiftUI中创建可编辑对象的动态列表,存储在手机本身
- git - "where ssh" 返回多个位置
- python-3.x - 当关键字被触发时,如何让机器人响应用户响应?
- python - 将整数除以列表
- python - 在 python 中使用 Fuzzymatcher 时如何确定截止值或阈值
- javascript - 如何在两个以上的画布中绘制 HTML 和 JS
- sql - 当天postgresql对应的item个数
- c - 十六进制值与 '\0' 的比较
- python - 为什么我在这个 pandas 数据框分配中丢失了 9 个值?