I want to geocode my location and display using gogle-maps-for-rails gem
View:
= gmaps({ "map_options" => { "auto_adjust" => true } })
= form_tag geocode_geo_locations_path, :method => :get, :remote => true do
= text_field_tag 'address'
= submit_tag 'search'
in my controller i:
def geocode
@location = Gmaps4rails.geocode(params[:address])
if @location
@location_hash = @location.map { |loc| {:longitude => loc[:lng], :latitude => loc[:lat], :address => loc[:matched_address]} }.first
end
end
and in the geocode.js.erb view
Gmaps4Rails.replace_markers(<%=raw @location_hash.to_json %>);
It works so far that I get a marker on the map, however the map does not get auto_adjusted. How can i do this?
source
share