Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Places API not returning place_id

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

like image 993
user1116573 Avatar asked Jun 25 '14 22:06

user1116573


1 Answers

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

like image 74
iam_martin Avatar answered Oct 31 '22 02:10

iam_martin