【问题标题】:How implement Gmaps4rails and autocomplete如何实现 Gmaps4rails 和自动完成
【发布时间】:2016-10-23 14:35:20
【问题描述】:

我真的很失望,我试图在我的应用程序上实现自动完成,但我不知道该怎么做。我在 Google、StackOverflow 上进行了搜索,但找不到要理解的内容……我只希望法国自动完成。

所以我尝试了这个,但是这段代码不起作用

我的观点(脚本和表单)

<%= 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})

我的应用程序.js

/= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require underscore
//= require gmaps/google
//= validyoutube
//= require_tree .

你能帮帮我吗?谢谢。

【问题讨论】:

    标签: google-maps autocomplete gmaps4rails


    【解决方案1】:

    为了帮助您开始实施,您可以尝试浏览这些有用的 GitHub 帖子:

    此外,还请尝试通过Place Autocomplete,其中提到地点自动完成请求是来自以下地址的 HTTP URL:

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

    并且,要将其设置为您的首选语言,请将language 参数添加到您的请求中,其值等于您选择的语言代码。请参阅list of supported languages 及其代码。

    您也可以查看gmaps4rails with Google Maps searchbox 中给出的解决方案,看看是否有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-23
      • 2012-12-02
      • 2018-04-23
      • 1970-01-01
      • 2010-10-03
      • 2011-07-19
      • 2012-08-04
      • 1970-01-01
      相关资源
      最近更新 更多