0

我正在使用 ym4r_gm 在我的网站上创建标记图。我创建了 1 个标记,可以使用以下代码。

@map = GMap.new("locations_map")
@map.control_init(:large_map => true,:map_type => true)
geocode = GMap::Geocoding.get("G12 8BZ")
@map.record_init @map.add_overlay(GMarker.new([geocode.first.latitude,geocode.first.longitude], :title => "Hillhead, Glasgow", :info_window =>"Hillhead, Glasgow"))

我将如何让一组标记显示在地图上?我有一组邮政编码(邮政编码),如下所示:

postcodes = ["G11 6PR", "G1 T3R", "G12 8BZ"]

我注意到 ym4r_gm 中的 MarkerGroup 类,但我无法弄清楚:-S

如果有人能给我一个很棒的帮助,这里也是文档的链接。

http://ym4r.rubyforge.org/ym4r_gm-doc/

任何帮助,将不胜感激。

干杯

伊夫

4

1 回答 1

0

不确定 ym4r_gm,但使用 ym4r_mapstraction 会是这样(尽管这将同时使用 ym4r_gm 和 ym4r_mapstraction,因为我认为 ym4r_mapstraction 没有方便的地理编码助手)

 @map = Mapstraction.new("map_div", :google)         
 @map.control_init(:small_map => true, :map_type => true)

   postcodes.each do |this_postcode|
     begin
        # might want to put the Geocoding part into a begin-rescue clause
        # in case postcode isn't valid

        returned_geocode = GMap::Geocoding.get(this_postcode)
        this_title = this_postcode
        new_marker = Marker.new([returned_geocode.first.lat.to_f, returned_geocode.first.lon.to_f], :info_bubble => this_title, :icon => "images/gmaps/blue_image.png")
        blue_markers.push(new_marker)
      rescue Exception => e
        logger.error e.inspect
      end
   end
 @map.marker_group_global_init(MarkerGroup.new(blue_markers, true),"BLUE")
于 2011-02-17T00:22:44.293 回答