Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API V3 - Anyway to retrieve Autocomplete results instead of dropdown rendering it?

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.

  • http://code.google.com/apis/maps/documentation/javascript/reference.html
  • http://code.google.com/apis/maps/documentation/places/index.html

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);
like image 657
Rafael Xavier Avatar asked Feb 14 '12 12:02

Rafael Xavier


People also ask

How do I get data from Google Maps API?

Go to APIs & Services → Dashboard → Enable APIs & Services at the top and Choose Maps Javascript API from the API Library. This will open up the Map JavaScript API page, and Enable it.

Is Google Maps API no longer free?

Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).


1 Answers

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.

like image 64
scottier Avatar answered Oct 02 '22 14:10

scottier