I've noticed the message about Google deprecating reference in favour of place_id
and was looking to implement it.
I am using the AutocompleteService
but when I run it the response does not contain place_id
, but does contain reference
and id
.
Here's a quick adaptation I did of the example page (I tried to put it on jsfiddle but couldn't get it to run):
<!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>
Can someone explain what I'm missing / doing wrong?
Has someone got an example of the AutocompleteService
with place_id
being returned with the predictions/suggestions?
Thanks
Issue 6845 Bug: Google Maps JavaScript API - Autocomplete Response not included place_id
https://code.google.com/p/gmaps-api-issues/issues/detail?id=6845&q=place_id&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal
UPDATE
This issue has been fixed
https://code.google.com/p/gmaps-api-issues/issues/detail?id=6845#makechanges
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With