Google Places API未返回place_id

时间:2014-06-25 22:11:49

标签: google-maps google-places-api

我注意到有关Google推荐使用place_id弃用引用的消息,并且正在寻求实施它。

我正在使用AutocompleteService,但在运行时,回复不包含place_id,但包含referenceid

这是我对示例页面做的快速改编(我试图把它放在jsfiddle但是无法让它运行):

<!DOCTYPE html>
<html>
<head>
<title>Retrieving Autocomplete Predictions</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<script>
// This example retrieves autocomplete predictions programmatically
// from the autocomplete service, and displays them as an HTML list.
// The predictions will include a mix of places (as defined by the
// Google Places API) and suggested search terms.

function initialize() {
  var service = new google.maps.places.AutocompleteService();
  service.getQueryPredictions({ input: 'trafalgar square' }, callback);
}

function callback(predictions, status) {
  if (status != google.maps.places.PlacesServiceStatus.OK) {
    alert(status);
    return;
  }

  var results = document.getElementById('results');

  for (var i = 0, prediction; prediction = predictions[i]; i++) {
    results.innerHTML += '<li>' + prediction.description + '</li>';
  }
}

google.maps.event.addDomListener(window, 'load', initialize);

</script>

</head>
<body>
  <p>Query suggestions for 'trafalgar square':</p>
  <ul id="results"></ul>
</body>
</html>

有人可以解释我遗失/做错的事吗?

是否有人得到AutocompleteService的示例,其中place_id与预测/建议一起返回?

由于

2 个答案:

答案 0 :(得分:4)

答案 1 :(得分:1)

我可以确认您所看到的内容。我猜我们只需要等待推出完成。