我想对我的位置进行地理编码并使用 google-maps-for-rails gem 显示
看法:
= gmaps({ "map_options" => { "auto_adjust" => true } })
= form_tag geocode_geo_locations_path, :method => :get, :remote => true do
= text_field_tag 'address'
= submit_tag 'search'
在我的控制器中,我有:
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
并在视图 geocode.js.erb
Gmaps4Rails.replace_markers(<%=raw @location_hash.to_json %>);
到目前为止,它工作得很好,我在地图上得到了一个标记,但是地图没有得到 auto_adjusted 。我怎么能做到这一点?