There seems to be very little documentation about Clustering with Google
Maps and Ym4r. I will happily write a HOWTO once I figure this out.
Anyway, here is my question (I already asked it on StackOverflow to no avail
and it can be referenced here):
http://stackoverflow.com/questions/2278778/google-maps-cluster-not-working-with-ym4r-gm
Onto the question...
I am attempting to get a Google Maps cluster working with ym4r_gm for Rails.
I know the general code works because every point is being displayed on the
map. The problem is that every point is being displayed on the map. I only
have like 350 points (right now) so its not too bad without clustering, but
I would like to have it working so that I can scale.
Relevant controller code:
def bizmap
@map = GMap.new( "map" )
@map.control_init( :large_map => true, :map_type => true )
@map.center_zoom_init( [ 40.228,-100.283 ], 1 )
markers = Array.new
Business.find(:all, :include => [:addresses], :conditions =>
["addresses.website_only != 1"]).each do |biz|
if (!biz.addresses.first.latitude.blank? and
!biz.addresses.first.longitude.blank?)
markers.push(
GMarker.new(
[biz.addresses.first.latitude,biz.addresses.first.longitude],
:title => biz.name,
:info_window => pretty_info_window( biz.name, biz.addresses.first
)
)
)
end
end
clusterer = Clusterer.new(markers, :min_markers_per_cluster => 2)
@map.overlay_init(clusterer)
end
Relevant view code:
<div id="aroundMeMapBox">
<%= GMap.header %>
<%= javascript_include_tag ''clusterer'' %>
<%= @map.to_html %>
<%= @map.div(:width => 600, :height => 400) %>
</div>
The relevant code generated by the view is here:
<script src="/javascripts/clusterer.js?1248062398"
type="text/javascript">
<script type="text/javascript">
var map;
window.onload = addCodeToFunction(window.onload,function() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(40.228,-100.283),1);map.addOverlay(new
Clusterer([addDescriptionToMarker(addInfoWindowToMarker(new
GMarker(new GLatLng(34.086,-83.8644),{title : "Georgia
Biz"}),"*Georgia Biz*
101 Main St.
Buford, Georgia 30519",{}),"Georgia Biz") ... (removed for
brevity)
map.addControl(new GMapTypeControl());
}
});
</script>
Thanks in advance for any help.
-e
--
Eric Lubow
w: eric.lubow.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ym4r-user/attachments/20100220/aa90dff5/attachment-0001.html>