sgruhier/typeahead-addresspicker

Have google output into text fields

Opened this issue · 2 comments

Any way to output the results that show up in the

 to output into individual text box fields?

same question here. I would to attach results into hidden inputs.

I guess you can assist with that peace of code:

<script>
  $( function() {
    // instantiate the addressPicker suggestion engine (based on bloodhound)
    var addressPicker = new AddressPicker({
      zoomForLocation: 18, 
      reverseGeocoding: true, 
      autocompleteService: {types: ['(cities)'], 
      componentRestrictions: {country: 'US'}}}
      );

    // instantiate the typeahead UI
    $('#address').typeahead(null, {
      displayKey: 'description',
      source: addressPicker.ttAdapter()
    });


    addressPicker.bindDefaultTypeaheadEvent($('#address'))

    $(addressPicker).on('addresspicker:selected', function (event, result) {
      html = ["Address: " + result.address()]
      // html.push("Latitude: " + result.lat())
      // html.push("Longitude: " + result.lng())
      html.push("<br>")
      html.push("<b>Long names:</b>")
      result.addressTypes().forEach(function(type) {
        html.push("  " + type + ": " + result.nameForType(type))
      })
      html.push("<br>")
      html.push("<b>Short names:</b>")
      result.addressTypes().forEach(function(type) {
        html.push("  " + type + ": " + result.nameForType(type, true))
      })
      html.push("<br>")
      $('#response').html( html.join('\n'))
    })
  })

</script>