I use GoogleMaps Places autocomplete, and I have a problem:
Currently, to validate, I must:
- enter the first letters of the city
- use the mouse and click on the desired result
- press the button "find"
This process works.
I would add the following process:
- enter the first letters of the city
- move with the UP / DOWN to move to the desired result
- press the "enter" key on my keyboard
Do you have a solution plz ?
Thank you very much
My view
<div class="home--searchbox">
<form class="geocoding form-inline">
<input placeholder="D'où partez vous ?" type="text" class="form-control"/>
<button class="btn btn-success disabled" data-urlto="<%= search_path %>">Find</button>
</form>
</div>
Googleplaces.coffee
$ ->
$('.geocoding')
.each (i, el) ->
$el = $(el)
$input = $el.find('input')
autocomplete = new google.maps.places.Autocomplete($input.get(0), types: ['geocode'])
$el.data 'autocomplete', autocomplete
google.maps.event.addListener autocomplete, 'place_changed', ->
$el.trigger 'address_selected'
.on 'focus', 'input', ->
autocomplete = $(this).parent().data('autocomplete')
if navigator.geolocation
navigator.geolocation.getCurrentPosition (position) ->
geolocation = new google.maps.LatLng position.coords.latitude, position.coords.longitude
autocomplete.setBounds new google.maps.LatLngBounds(geolocation, geolocation)
.on 'address_selected', ->
place = $(this).data('autocomplete').getPlace()
lat = place.geometry.location.lat()
long = place.geometry.location.lng()
city = $.grep(place.address_components, (component) ->
component.types[0] == 'locality'
)[0].long_name
address = place.formatted_address
$(this).find('button')
.data
lat: lat
long: long
city: city
address: address
.removeClass('disabled')
.on 'click', 'button', (e) ->
e.preventDefault()
data = $(this).data()
urlto = data.urlto
delete data.urlto
url = "#{urlto}?#{$.param data}"
document.location = url