6

I need to render the results of google.maps.places.Autocomplete in a custom way, instead of the default drop down menu.

Is there any way I can use the Google Maps API V3 to retrieve the same info of Autocomplete, but in an Array per request instead of the API do the rendering for me?

PS1:

I wondered I could use the google.maps.places.PlaceSearchRequest. But, differently from Autocomplete, it restricts my location. It cannot be used to search worldwide.

PS2:

The default way I am (currently) using Autocomplete restricts me. I must pass an input element, and the API renders the dropdown, which I do NOT want.

var autocomplete, input_el, place_changed_trigger_func;
input_el = <an input element>;
place_changed_trigger_func = function() {
  var place = autocomplete.getPlace();
  // do whatever you want with place
};
autocomplete = new google.maps.places.Autocomplete(input_el, {types: ["geocode"]});
google.maps.event.addListener(autocomplete, 'place_changed', place_changed_trigger_func);
ekad
  • 14,436
  • 26
  • 44
  • 46
Rafael Xavier
  • 2,840
  • 27
  • 34

3 Answers3

4

I believe this is the link that @jegnag meant to include.

https://developers.google.com/maps/documentation/javascript/places-autocomplete#place_autocomplete_service

You can access the array of results (places in addition to suggested search terms), you can even add your own custom results to this array, and display everything however you choose.

scottier
  • 248
  • 2
  • 10
  • I could not test it. But, looking at the documentation I guess this is exactly what I needed by that time. I am glad Google made it. – Rafael Xavier Jun 04 '14 at 00:03
1

Try the AutocompleteService class:

"You can use the AutocompleteService class to retrieve the query or place prediction data returned from the Autocomplete service. Calling either the getPlacePredictions() or getQueryPredictions() methods will return an array of five prediction objects of the form:"

jeznag
  • 4,183
  • 7
  • 35
  • 53
1

Have you explored the Autocomplete function of the Places API webservice? That appears to be what you're looking for.

Mano Marks
  • 8,761
  • 3
  • 27
  • 28