Ich bin wirklich enttäuscht, ich versuche Autocomplete auf meiner App zu implementieren, aber ich weiß nicht, wie das geht. Ich suchte auf Google, StackOverflow, aber ich kann nicht etwas finden, um zu verstehen ... Ich möchte Autocomplete nur für Frankreich.Wie implementieren Gmaps4rails und Autocomplete
So versuche ich dies aber dieser Code nicht funktionieren
Meine Ansicht (Drehbuch und Form)
<%= 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>
-Controller
@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})
Mein application.js
/= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require underscore
//= require gmaps/google
//= validyoutube
//= require_tree .
Können Sie mir helfen? Vielen Dank.
danke für deine antwort :) ich werde das versuchen. – nicolaswecandoit