Map center/zoom problems in ym4r

I am trying to show a list of events and their locations in a map in
my index action. I use will pagination for paginating through the
events. The first call to the page is a regular “html” format and the
subsequents calls are ajax calls. I initialize the map and markergroup
that contains the event markersin the first call to index page, for
subsequent ajax requests i bind the browser variables with the rubu
variables and add/remove event markers from the group. It all works
fine, but if lets say there are 2 markers 1 in new york the other in
san fran, i want the map to automatically adjust zoon to show all
markers in the map, but it just shows either one. if i call
“centerandzoomonmarkwrs” on the group then the map centers on east
coast of africa!

index action


def index
@events = Event.paginate(:page => params[:page], :per_page =>
2,
:order => “updated_at DESC”)
unless request.xhr?
build_index_map@events
else
@map = Variable.new(“map”)
@group = Variable.new(“event_marker_group”)
@markers = get_markers(@events)
end

    respond_to do |format|
        format.html # index.html.erb
        format.xml  { render :xml => @events }
        format.js
    end
end


def build_index_map(events)
    @map = GMap.new("map_div_id")
    @map.control_init(:large_map => true, :map_type => true)
    ll = Address.get_lat_long(events.first.address)
    # to center on usa -

@map.center_zoom_init([38.134557,-95.537109],4)
@map.center_zoom_init(ll, 4)

    @event_addresses = Event.get_addresses_of_events(events)
    @markers = Hash.new
    @event_addresses.each do |event, address|
        @markers[event.id] = GMarker.new(address,:title =>

event.title,
:info_window => event.description)
end
group = GMarkerGroup.new(true, @markers)
@map.overlay_global_init(group, “event_marker_group”)
@map.record_init group.center_and_zoom_on_markers
end

def get_markers(events)
    @event_addresses = Event.get_addresses_of_events(events)
    @markers = Hash.new
    @event_addresses.each do |event, address|
        @markers[event.id] = GMarker.new(address,:title =>

event.title,
:info_window => event.description)
end
return @markers
end


index.rjs


page.replace “events_list”, :partial => “events_index”
page << @map.clear_overlays
page << @group.clear
page << @group.activate
@markers.each {|key, value| page << @group.addMarker(value, key)}
page << @map.add_overlay(@group)
page << @group.centerAndZoom