apneadiving/Google-Maps-for-Rails — Issue #118: Cannot Update Markers
Author: RozKen
Created: 2011-11-16 06:53:42+00:00
State: open

Hello I'm Ken. And I'm new to RubyOnRails.
I apologize if this is an awkward question in here.

I'd like to find display markers which are the nearest to the address input on form.
But the markers cannot update.

I suspect 'Gmaps.loadMaps();'.
I read source code of index.html in my browser, there are javascripts which are including data acquired from SQL.
I suppose the data should not be static.

How can I update markers on Google Maps?
Thanks.

Here are my code structure

===index.html.erb===
<%= form_tag '/nearest/change', :remote => true, :method => 'GET' do %>
<%= text_field "search", "address", "size" => 20 %>
<%= submit_tag 'submit' %>
<% end %>

<%= render 'list' %>
<%= render 'map' %>

=== _list.html.erb ===

address

...

=== _map.html.erb ===

<%= gmaps4rails(@map_data) %>

=== change.js.erb ===
$("#list").html("<%= escape_javascript(render :partial => 'list', :object => @data)%>");
$("#map_location").html("<%= escape_javascript(render 'map') %>");
Gmaps.loadMaps();

=== nearest_controller.rb ===
def change
@data = Nearest.where(:id => 1) #easiest filtering
@map_data = @data.to_gmaps4rails
end