谁能告诉我为什么我不能从谷歌 API 获得城市列表

Can anyone tell me why cannot i get a list of cities from google apis?

本文关键字:API 城市 列表 谷歌 告诉我 为什么 不能      更新时间:2023-09-26

这是代码

<script>
    $.ajax({
        url: "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=(cities)&language=pt_BR&key=AIzaSyA8FpY17IMXOcKg7Zwzdv2GdTQLR3OnTTk",
        type: "GET",
        dataType: 'jsonp',
        cache: false,
        success: function (response) {
            console.log(response);
        }
    });
</script>

在我上面执行后,我总是收到此错误。

maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=(花旗...nTTk&callback=jQuery1111044755223696120083_1455461549950&_=1455461549951:2 未捕获的语法错误: 意外令牌 :

places-webservice(目前(不支持JSONP或XDomainRequests。

要从客户端请求自动完成预测,您必须使用 places 库的自动完成服务(它是 Maps-javascript-API 的库(

google.maps.event.addDomListener(window,'load',function() {
  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: 'Vict',types:['(cities)'] }, displaySuggestions);
});
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&language=pt-BR"></script>
<img src="https://developers.google.com/places/documentation/images/powered-by-google-on-white.png"/>
<ul id="results"></ul>