Google map auto-fill selects the first entry in the default list

I use gmap autocomplete, and sometimes the user does not fall into any list of offers. For example, he types “Paris” in the input field and believes that the search will be performed with Paris, however, “place_changed” from gmap auto-completion has never been called, the search cannot be performed. How to choose by default the first option of the list of offers when the user does not make a choice? I believe that I can adapt the solution provided for the "introductory problem" described here ( Google maps Places API V3 autocomplete - select the first option when entering ) with the blur event handling, however this will not work.

Any clues?

+5
source share
1 answer

I think this is a kind of victory for the goal of the car.

You can simply program autofill predictions as follows:

function initialize() 
{
    var service = new google.maps.places.AutocompleteService();
    service.getQueryPredictions({ input: 'some address' }, callback);
}

function callback(predictions, status) 
{
   if (status != google.maps.places.PlacesServiceStatus.OK) 
   {
      alert(status);
      return;
   }  

   // Take the first result
   var result = predictions[0]

   // do as you wish with the result    
}

Hope that helps

+3
source

All Articles