制图师显示正确的信息框但错误的标记

时间:2012-03-10 03:54:28

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-plugins

我正在尝试创建一个带有从DB中提取的分配器标记的地图。我能够成功地做到这一点,但是,每当我点击标记时,信息框总是出现在同一个标​​记上。 CORRECT饮水机的信息框在地图上弹出,但错误的标记!是否有人遇到过这个问题?

在我的控制器中:

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> 

1 个答案:

答案 0 :(得分: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)