Google Map Markers in YM4R/GM
By chris on November 28th 2007 in /dev/rails | 1,703 views
When using YM4R/GM, by Guilhem Vellut, in your Rails app chances are you’ll want to mark points on the map using custom icons. The means to do so is not readily apparent or straight-forward. I’ve found that this works well:
map = GMap.new( Constants::GM_DIV_ID, Constants::GM_NAME )
# Define the start and end icons
map.icon_global_init( GIcon.new( :image => "/images/google_maps/icong.png", :icon_size => GSize.new( 24,38 ), :icon_anchor => GPoint.new(12,38), :info_window_anchor => GPoint.new(9,2) ), "icon_start")
map.icon_global_init( GIcon.new( :image => "/images/google_maps/iconr.png", :icon_size => GSize.new( 24,38 ), :icon_anchor => GPoint.new(12,38), :info_window_anchor => GPoint.new(9,2) ), "icon_stop" )
icon_start = Variable.new("icon_start"); icon_stop = Variable.new("icon_stop")
if respond_to?( "start_lat" ) && respond_to?( "start_long" )
map.center_zoom_init( [start_lat, start_long], Constants::GM_ZOOM )
map.overlay_init( GMarker.new( [start_lat, start_long], { :icon => icon_start, :title => name + ” start”, :info_window => “start” } ) )
end
if respond_to?( “end_lat” ) && respond_to?( “end_long” )
map.overlay_init( GMarker.new( [end_lat, end_long], { :icon => icon_stop, :title => name + ” end”, :info_window => “end” } ) )
end

georges responded on 16 Jun 2008 at 11:47 am #
this was helpful, the docs aren’t very clear on custom icons.
Jason Darrow responded on 23 Nov 2008 at 8:26 am #
You have no idea how much time I burned on this before running across your post here. Thank you for stopping the pain.
Sam Scehnkman-Moore responded on 24 Dec 2008 at 12:03 pm #
Like the others, THANK YOU