0

I'm using Google Maps Places V3 autocomplete. I would like to have a functionality where if a user starts typing an word into the searchfield and press enter , the first item from the autocomplete drop down is should be selected. like on http://www.onradpad.com/.

I have found many threads on SO on this topic but i cant get the exact results.Help me with this issue.

<!doctype html>
<html>
  <head>
    <script src="http://maps.google.com/maps/api/js?libraries=places&region=uk&language=en&sensor=false"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function(e){
        var compformautoaddrfill = new google.maps.places.Autocomplete(document.getElementById('compAddr'), {
          componentRestrictions: {country: "be"}
        });
        google.maps.event.addListener(compformautoaddrfill, 'place_changed', function() {
          console.log(compformautoaddrfill.getPlace().address_components.length,compformautoaddrfill.getPlace());
        });
      });
    </script>
  </head>
  <body>
    <input type="text" id="compAddr">
  </body>
</html>

JSFIDDLE

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
user3383301
  • 1,891
  • 3
  • 21
  • 49
  • Which are the other threads that you mention? Why their answers do not apply to your use case? – givanse Mar 20 '14 at 19:05
  • 1
    look at this thread https://stackoverflow.com/questions/7865446/google-maps-places-api-v3-autocomplete-select-first-option-on-enter But it returns incorrect answers – user3383301 Mar 20 '14 at 19:08
  • See the [second answer](http://stackoverflow.com/questions/7865446/google-maps-places-api-v3-autocomplete-select-first-option-on-enter#11703018), the [fiddle](http://jsfiddle.net/amirnissim/2D6HW/) is working. – Mosh Feu Mar 16 '16 at 08:06

0 Answers0