use*_*573 8 google-maps google-places-api
我已经注意到关于谷歌弃用引用的消息,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>
Run Code Online (Sandbox Code Playgroud)
有人可以解释我错过了什么/做错了吗?
有人得到了一个与预测/建议AutocompleteService一起place_id返回的例子吗?
谢谢
问题 6845 Bug:Google Maps JavaScript API - 未包含自动完成响应 place_id
更新
这个问题已被解决
https://code.google.com/p/gmaps-api-issues/issues/detail?id=6845#makechanges
| 归档时间: |
|
| 查看次数: |
1408 次 |
| 最近记录: |