2012-03-10 39 views
0

我試圖創建一個地圖,標記爲從DB中拉出的分配器。我可以成功地做到這一點,但是,每當我點擊標記時,信息框總是出現在相同的標記上。正確的飲水機信息框在地圖上彈出,但在錯誤的標記上!有沒有人遇到過這個問題?製圖員顯示正確的信息框,但錯誤的標記

在我的控制器:

def find_map 

    @location = Location.new 
    @location.address = params[:location][:address] 
    @latlon = @location.geocode 
    @dispensers = Dispenser.near(@latlon) 
    @numrecords = 0 
    @lat = [] 
    @long = [] 
    @user_id = [] 
    @dispensers.each do |x| 
     @lat[@numrecords] = x.latitude 
     @long[@numrecords] = x.longitude 
     @user_id[@numrecords] = x.user_id 
     @numrecords += 1 
    end 

    @map = Cartographer::Gmap.new('map') 
    @map.zoom = :bound 
    @icon = Cartographer::Gicon.new() 
    @map.icons << @icon 

    @count = 0 
    @numrecords.times do 
     markername = "marker#{@count}" 
     markername = Cartographer::Gmarker.new(:name=> "Business", :marker_type => "Building", 
          :position => [@lat[@count], @long[@count]], 
          :info_window_url => "/bio/#{@user_id[@count]}", :icon => @icon) 

     @map.markers << markername 
     @count += 1 
    end 

在我show.html.erb

<%= raw Cartographer::Header.new.to_s %> 
    <%= raw @map.to_html %> 

    <div style="width:350px;height:250px;" id="map" > [Map]</div> 

回答

0

好消息,我想它了。在下面的代碼中,我不得不向商家名稱添加#{@ count} ...我假設標記位置設置爲 位置,並且信息框位置設置爲與標記 相同:name屬性,這可能是循環創建的最後一個標記 。

謝謝!

markername = Cartographer::Gmarker.new(:name=> "Business#{@count}", :marker_type => "Building", 
          :position => [@lat[@count], @long[@count]], 
          :info_window_url => "/bio/#{@user_id[@count]}", :icon => @icon)