2016-11-03 7 views
0

私のアプリでGoogleの場所を使用しています。すべて正常に動作しますが、入力から国を削除または無視したいだけです。Google place autocomplete remove country to query

例えばそれが入力した場合、 "アーク" 私は私が欲しい私はこのquery=Arcachon%2C+France

のようなクエリを持ってクリックした後

Arcachon, France 
Arcueil, France 
Archamps, France 

...

を持っているだけで、このquery=Arcachonと削除または無視%2C+France

home.html.erb

<%= form_tag(result_path, method: :get) %> 
    <%= text_field_tag :query, params[:query], class:"search-query form-control", placeholder:"Ex: Corse, Arcachon..." %> 
    <%= submit_tag "Partez", class:"btn btn-danger", name: nil %> 


<script> 
    function init() { 
    var options = { 
     types: ['(cities)'], 
     componentRestrictions: {country: "fr"}}; 
    var input = document.getElementById('query'); 
    var autocomplete = new google.maps.places.Autocomplete(input, options);} 

    google.maps.event.addDomListener(window, 'load', init); 
</script> 

私のjs model.rbからの私のクエリあなたの助けを

def self.search(query) 
    return scoped unless query.present? 
    where(['nomdep LIKE ? OR name LIKE ? OR nomregion LIKE ? OR commune LIKE?', "%#{query.mb_chars.downcase}%", "%#{query.mb_chars.downcase}%", "%#{query.mb_chars.downcase}%", "%#{query.mb_chars.downcase}%"]) 
    end 

とコントローラ

def result 
     if params[:query].blank? 
     redirect_to action: :index and return 
     else 
     @campings = Camping.search(params[:query]) 
    end 
end 

感謝。

答えて

0

誰かが

ソリューションだけregion=FR

<script src="https://maps.google.com/maps/api/js?v=3.23&key=MYKEY=places&region=FR"></script> 

このように追加で支援が必要な場合、私は:)この質問を解決しました
関連する問題