Forum: Ruby on Rails Ajax-based Google Map Not Updating

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
96956a77a329c7f8622e7c81396655fd?d=identicon&s=25 Justin Williams (Guest)
on 2007-02-15 23:22
(Received via mailing list)
I am working on building a Google Map application that lets a user
search a database by clicking on several check boxes to filter
results.  I have attached an observe_form call that sends the selected
checkboxes to my controller.  The controller then searches the
database and re-renders the Google map (rendered as a partial).  The
map is rendered and I call the initialize method on the map again.

The issue I am having is that when I perform the new search and update
the map, it update the points that are on the map.

Any help is appreciated.

The search results code and RJS is here:

    @tutors = Tutor.find(:all, :conditions => ["work_lat != '' and
work_long != '' and id in (select tutor_id from subjects_tutors where
subject_id in (#{@query}))"])

    respond_to do |format|
    format.js {
    render :update do |page|
      page.replace 'mapresults', :partial => "map", :locals =>
{:tutors => @tutors} "initialize"

Here's the map rendering code:

<script type="text/javascript">
  if (window.addEventListener) {
    window.addEventListener("load", initialize, false);

  function createMarker(point,html) {
    var marker1 = new GMarker(point);
    GEvent.addListener(marker1, "click", function() {

    return marker1;

  function initialize() {
    var map = new GMap(document.getElementById("map"));
    map.addControl(new GSmallMapControl());

    <% unless params[:student_lat] and params[:student_long] %>
      map.centerAndZoom(new GPoint(-122.443882, 37.769079), 5);
    <% else %>
      map.centerAndZoom(new GPoint(<%= params[:student_long].to_f %>,
params[:student_lat].to_f %>), 5);
    <% end %>

    <% unless @tutors.size == 0 %>
      <% @tutors.each do |tutor|%>
        var point = new
        var marker = createMarker(point,'<div><h3><%= link_to
h(tutor[:first] + " " + tutor[:last]), edit_tutor_path(tutor) %> </
h3><p><%= mail_to tutor.emails.primary.address %><br /><%=
tutor.phones.primary.digits %><br /><strong>Rating</strong>: <%=
tutor.rating %>/5 stars</p></div>');
      <% end %>
    <% end %>


Justin Williams
Owner, Second Gear
This topic is locked and can not be replied to.