javascript - Google 地图和地点 API 超出了您对此 API 的请求配额
问题描述
我在 000webhost 上创建了网站。我在上面使用地图并创建新的google api密钥,但问题是当我第一次通过消息点击api时超出了你的“此API的请求配额”,在我第一次点击api之前我从来没有点击过它新的 API 密钥。这是我的 php 脚本。我需要帮助
function initMap() {
var map = new google.maps.Map(document.getElementById('show_map'), {
center: {lat: 33.6518, lng: 73.1566},
zoom: 13
});
var input = document.getElementById('shopadd');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'pk'}
};
var autocomplete = new google.maps.places.Autocomplete(input,options);
// Bind the map's bounds (viewport) property to the autocomplete object,
// so that the autocomplete requests use the current map bounds for the
// bounds option in the request.
autocomplete.bindTo('bounds', map);
// Set the data fields to return when the user selects a place.
autocomplete.setFields(['address_components', 'geometry', 'name']);
autocomplete.setOptions({strictBounds: true});
var infowindow = new google.maps.InfoWindow();
var infowindowContent = document.getElementById('infowindow-content');
infowindow.setContent(infowindowContent);
var marker = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});
autocomplete.addListener('place_changed', function() {
infowindow.close();
marker.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
// User entered the name of a Place that was not suggested and
// pressed the Enter key, or the Place Details request failed.
window.alert("No details available for input: '" + place.name + "'");
return;
}
var location = "Address " + place.formatted_address;
location += "Latitude " + place.geometry.location.lat();
location += "Longitude " + place.geometry.location.lng();
var lat = place.geometry.location.lat();
document.getElementById('lat').value = lat;
var lng = place.geometry.location.lng();
document.getElementById('lng').value = lng;
// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
marker.setPosition(place.geometry.location);
marker.setVisible(true);
var add = '';
if (place.address_components.length>0) {
add = add.concat(
(place.address_components[0] && place.address_components[0].short_name || ''),' ',
(place.address_components[1] && place.address_components[1].short_name || ''),' ',
(place.address_components[2] && place.address_components[2].short_name || ''),' ');
}
document.getElementById('add').value = add;
infowindowContent.children['place-icon'].src = place.icon;
infowindowContent.children['place-name'].textContent = place.name;
infowindowContent.children['place-address'].textContent = add;
infowindow.open(map, marker);
});
// Sets a listener on a radio button to change the filter type on Places
// Autocomplete.
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key="my key"&libraries=places&callback=initMap" async defer></script>
解决方案
谷歌改变了他们的定价模式。新计划为您提供了更大的灵活性,并可以控制您如何使用我们的 API。您可以根据需要使用尽可能多或尽可能少的使用量,并且只需为您每月使用的量付费。
截至 2018 年 7 月 16 日:
- Google Maps Platform API 按 SKU 计费。
- 跟踪每个产品 SKU 的使用情况,一个 API 可能有多个产品 SKU。
- 成本计算方式为:SKU 使用 x 每次使用的价格。
- 对于每个结算帐户,对于符合条件的 Google Maps Platform SKU,每月可获得 200 美元的 Google Maps Platform 信用额度,并自动应用于符合条件的 SKU。
欲了解更多信息,请访问此链接
推荐阅读
- mysql - 如何使用多个 JOIN 加速 SQL 查询?
- java - java.lang.NoClassDefFoundError: org/elasticsearch/script/mustache/SearchTemplateRequest
- php - 将自定义帖子类型标题添加到数组
- flutter - 我如何在颤振中动态设置变量的数据?
- node.js - 特定 Bucket 文件夹上的 Cloud Function 存储触发器
- asp.net-core - PageModel.RedirectToPage() 在没有 /Index 页面的情况下调用时抛出 InvalidOperationException
- python - 如何从 python 代码动态 pip 安装 .whl 文件,然后使用该库
- notepad++ - notepad++ (NppScript) 我怎样才能替换 sctipt?
- javascript - 如何检查大写锁定是否打开?
- php - 如何在 PHP 中循环来自多维数组的数据并将其注入 HTML