2016-10-23 10 views
0

私は本当にdisapointed、私は私のアプリでオートコンプリートを実装しようとしているが、私はそれを行う方法を知らない。私はGoogleでStackOverflowを検索しましたが、理解できるものは見つけられません...私はフランスのみのオートコンプリートをしたいと思います。どのようにGmaps4railsとオートコンプリートを実装する

だから私はこれをしようとしたが、このコードは

マイビュー(スクリプトおよびフォーム)

<%= 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> 
handler = Gmaps.build('Google'); 
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 
markers = handler.addMarkers(<%=raw @hash.to_json %>); 
handler.bounds.extendWith(markers); 
handler.fitMapToBounds(); 

}); 
$(document).ready(initialize_gmaps_autocomplete_user_address()); 

function initialize_gmaps_autocomplete_user_address() { 
var input = document.getElementById('query'); 
var autocomplete = new google.maps.places.Autocomplete(input); 
autocomplete.setTypes(['geocode']); 
} 
</script> 

コントローラ

@hash = Gmaps4rails.build_markers(@campings) do |camping, marker| 
     marker.lat camping.latitude 
     marker.lng camping.longitude 
     marker.infowindow render_to_string(:partial => "/campings/infowindow", :locals => { :camping => camping}) 
     marker.picture ({ 
      "url" => "http://avantjetaisriche.com/map-pin.png", 
      "width" => 29, 
      "height" => 32}) 

私application.js

/= require jquery 
//= require jquery_ujs 
//= require turbolinks 
//= require bootstrap-sprockets 
//= require underscore 
//= require gmaps/google 
//= validyoutube 
//= require_tree . 
を動作しません。

私を助けることができますか?ありがとう。

答えて

0

は、あなたがこれらの有用GitHubの記事を通過しようとして、あなたが実装を開始する助けには:

、またそれがあった前記Place Autocompleteを経由してみてくださいプレイスのオートコンプリートリクエストは、次のURLのHTTP URLです:

https://maps.googleapis.com/maps/api/place/autocomplete/output?parameters 

そして、ご希望の言語に設定するには、ご希望の言語コードに等しい値でlanguageパラメータをリクエストに追加してください。 list of supported languagesとそのコードをご覧ください。

gmaps4rails with Google Maps searchboxで解決策を確認し、役立つかどうかを確認することもできます。

+0

あなたの返信に感謝:)私はこれを試してみます。 – nicolaswecandoit

関連する問題