2011-02-16 91 views
0

我正在使用ym4r_gm在我的网站上创建标记地图。我用下面的代码创建了1个很好的标记。Ruby on Rails ym4r_gm Google地图

@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/

任何帮助,将不胜感激。

干杯

EEF

+0

仅供参考:https://github.com/apneadiving/Google-Maps-for-Rails – apneadiving 2011-02-16 16:48:38

回答

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")