2011-02-16 150 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")