【发布时间】:2014-06-25 22:11:49
【问题描述】:
我注意到有关 Google 弃用引用以支持 place_id 的消息,并正在寻求实施它。
我正在使用AutocompleteService,但是当我运行它时,响应不包含place_id,但包含reference 和id。
这是我对示例页面所做的快速修改(我尝试将其放在 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 与预测/建议一起返回?
谢谢
【问题讨论】:
标签: google-maps google-places-api