【发布时间】:2016-10-27 23:20:21
【问题描述】:
我正在开发一个项目,我必须使用 google places api for web。我正在使用 google api 作为位置名称下拉菜单。当我填写位置名称时,我会收到此回复。我已经生成了 api 密钥并将其嵌入了我的代码,但这似乎不起作用。有什么建议吗?
/**/xdc._62n6tn && xdc._62n6tn( [3,null,null,"此服务需要 >API 密钥。更多信息 关于身份验证和 Google Maps Javascript API 服务请参阅:>https://developers.google.com /maps/documentation/javascript/get-api-key"])
编辑: 好的,这是代码
<!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>
【问题讨论】:
-
请提供一个Minimal, Complete, Tested and Readable example 来证明该问题。听起来您没有正确包含密钥或没有激活密钥。
-
你确定“abcd”是你的钥匙吗?正如我在您的代码底部看到的那样。将正确的密钥放在那里。
-
我已经添加了所有细节。请看一看。
-
您是否在控制台中启用了 Google Maps Javascript API。检查您是否正确启用了此 API 的 API 密钥。它肯定会工作。
-
我用你的代码尝试了我的 API 密钥,它成功了!!告诉我一件事你正在创建服务器或浏览器什么样的 API 密钥?或者只是禁用 Google Maps Javascript API 并再次启用,然后生成一个新密钥。
标签: javascript api google-maps