1.打开Google Cloud Console,进入API Manager。 2.选择你希望移除限制的API,点击它。 3.在左侧面板中,点击“密钥”选项卡。 4.找到你想要移除限制的密钥,并选择“编辑”。 5.在弹出的窗口中,找到“应用程序限制”部分,将“限制应用程序”更改为“不受限制”。 6.保存更改并重新使用密钥。
示例代码:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY');
xhr.onload = function() {
if (xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
console.log(response.results[0].formatted_address);
}
else {
console.log('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();