Google放置API密钥错误 [英] Google places API key error
问题描述
我正在开发一个项目,我必须使用谷歌地点api for web。我正在使用谷歌API的位置名称下拉菜单。当我填写地点名称时,我收回了这个回复。我已经生成了API密钥并将其嵌入到我的代码中,但这似乎不起作用。任何建议?
I am developing a project and I have to use google places api for web. I am using google api for location name drop down menu. When I fill out location name, I am getting back this response. I have generated api key and embedded it my code but this doesn't seem to be working. Any suggestion?
/ ** / xdc ._ 62n6tn&& xdc ._ 62n6tn([3,null,null,此服务需要一个> API密钥。 https://developers.google.com =nofollow> https://developers.google.com
/ maps / documentation / javascript / get-api-key])
/**/xdc._62n6tn && xdc._62n6tn( [3,null,null,"This service requires an >API key. For more information on authentication and Google Maps Javascript API services please see: >https://developers.google.com /maps/documentation/javascript/get-api-key"] )
编辑:
确定这里是代码
edit: Ok here's the code
<!DOCTYPE html>
<html>
<head>
<title>Retrieving Autocomplete Predictions</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
#right-panel {
font-family: 'Roboto','sans-serif';
line-height: 30px;
padding-left: 10px;
}
#right-panel select, #right-panel input {
font-size: 15px;
}
#right-panel select {
width: 100%;
}
#right-panel i {
font-size: 12px;
}
</style>
</head>
<body>
<div id="right-panel">
<p>Query suggestions for 'Taxi Services near NewY':</p>
<ul id="results"></ul>
</div>
<script>
function initService() {
var displaySuggestions = function(predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
predictions.forEach(function(prediction) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(prediction.description));
document.getElementById('results').appendChild(li);
});
};
var service = new google.maps.places.AutocompleteService();
service.getQueryPredictions({ input: 'Taxi Services near NewY' }, displaySuggestions);
}
</script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIza---------------------&</script>
以下是
google api设置
推荐答案
我认为您缺少步骤
1.转到Google Developers Console
2.启用Google Maps JavaScript API
3.然后生成API密钥
4.然后将该API密钥放在代码底部。
I think you are missing steps . 1. Go to Google Developers Console. 2. Enable Google Maps Javascript API. 3. Then Generate API key . 4. Then put that API key in the bottom of your code in this section.
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_MAPS_JAVASCRIPT_API_KEY&libraries=places&callback=initService"
async defer></script>
%工作,如果仔细按照步骤。
This will 100% work, if follow the steps carefully.
这篇关于Google放置API密钥错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!