Need Help with Consolidating RoR Google Map Results
Posted
by Kevin
on Stack Overflow
See other posts from Stack Overflow
or by Kevin
Published on 2010-04-12T03:46:22Z
Indexed on
2010/04/12
3:53 UTC
Read the original article
Hit count: 309
I have a project that returns geocoded results within 20 miles of the user. I want these results grouped on the map by zip code, then within the info window show the individual results. The code posted below works, but for some reason it only displays the 1.png rather than looking at the results and using the correct .png icon associated with the number. When I look at the infowindows, it displays the correct png like "/images/2.png" or "/images/5.png" but the actual image is always 1.
@ziptickets = Ticket.find(:all,
:origin => coords,
:select => 'DISTINCT zip, lat, lng',
:within => @user.distance_to_travel,
:conditions => "status_id = 1")
for t in @ziptickets
zips = Ticket.find(:all, :conditions => ["zip = ?", t.zip])
currentzip = t.zip.to_s
tixinzip = zips.size.to_s
imagelocation = "/images/" + tixinzip + ".png"
shadowlocation = "/images/" + tixinzip + "s.png"
@map.icon_global_init(GIcon.new(:image => imagelocation,
:shadow => shadowlocation,
:shadow_size => GSize.new(60,40),
:icon_anchor => GPoint.new(20,20),
:info_window_anchor => GPoint.new(9,2)), "test")
newicon = Variable.new("test")
new_marker = GMarker.new([t.lat, t.lng], :icon => newicon, :title => imagelocation, :info_window => currentzip)
@map.overlay_init(new_marker)
end
I tried changing the last part of the mapicon from:
:info_window_anchor => GPoint.new(9,2)), "test")
newicon = Variable.new("test")
to:
:info_window_anchor => GPoint.new(9,2)), currentzip)
newicon = Variable.new(currentzip)
but the strangest thing is that any string that has numbers in it causes the map to fail to render in the view and just show a blank screen... same if I replace it with
:info_window_anchor => GPoint.new(9,2)), "123")
newicon = Variable.new("123")
Any advice would be helpful... also it runs a bit slower than my previous code which just set up 4 standard icons and used them outside of the loop so any hints as to speed up execution would be appreciated greatly.
Thanks!
© Stack Overflow or respective owner