【问题标题】:Google places API key errorGoogle 放置 API 密钥错误
【发布时间】: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>

这是 google api settings

【问题讨论】:

  • 请提供一个Minimal, Complete, Tested and Readable example 来证明该问题。听起来您没有正确包含密钥或没有激活密钥。
  • 你确定“abcd”是你的钥匙吗?正如我在您的代码底部看到的那样。将正确的密钥放在那里。
  • 我已经添加了所有细节。请看一看。
  • 您是否在控制台中启用了 Google Maps Javascript API。检查您是否正确启用了此 API 的 API 密钥。它肯定会工作。
  • 我用你的代码尝试了我的 API 密钥,它成功了!!告诉我一件事你正在创建服务器或浏览器什么样的 API 密钥?或者只是禁用 Google Maps Javascript API 并再次启用,然后生成一个新密钥。

标签: javascript api google-maps


【解决方案1】:

我认为您缺少步骤。 1. 转到谷歌开发者控制台。 2.启用谷歌地图Javascript API。 3. 然后生成 API 密钥。 4. 然后将该 API 密钥放在本节代码的底部。

<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>

如果仔细按照步骤操作,这将 100% 有效。

【讨论】:

  • 我多么愚蠢。谢谢你救了我的命:)
猜你喜欢
  • 2013-08-26
  • 1970-01-01
  • 2020-10-13
  • 2017-04-17
  • 1970-01-01
  • 2021-06-08
  • 2015-09-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多