Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
& Rails
Why Google Maps?
Why Google Maps?
• # => Australia
YM4R
• Inject Markers
YM4R
• Inject Markers
@map.overlay_init(GMarker.new([-28.99425, 132.03845],
:title => “Australia”,
:info_window => “Yay!”))
YM4R
def index
@map = GMap.new(“map_div”)
@map.control_init(:large_map => true,:map_type => true)
@map.center_zoom_init([75.5,-42.56],4)
@map.overlay_init(GMarker.new([75.6,-42.467],:title => “Hello”,
:info_window => “Info! Info!”))
end
You can also add multiple markers So I find all my dealers in the DB.
and have YM4R set how the max Create a new GMap instance
number to be shown before it Set controls and the center, then I create
“clumps” them together as 1 marker, a new array and assign it to the variable
and all sorts of stuff. markers. From there I “push” into the
This is the controller code from the array each of the db records
orbea site I created. Then we use YM4R’s clusterer class, where
we tell it the array of markers and the
max-Number of visible markers.
YM4R
def find_a_dealer
@dealers = Dealer.find(:all, :order => “name ASC”)
@map = GMap.new(“map_div”)
@map.control_init(:large_map => true, :map_type => true)
@map.center_zoom_init([-28.99425, 132.03845], 4)
markers = Array.new
@dealers.each do |dealer|
markers << GMarker.new([dealer.lat, dealer.lng],
:info_window => “<strong>#{dealer.name}</strong><br />
#{dealer.street_number}, #{dealer.street_name.capitalize},<br />
#{dealer.suburb.capitalize}, #{dealer.state.upcase}, #{dealer.postcode}<br />
PH: #{dealer.phone_number}, #{dealer.suburb.upcase}, #{dealer.state.upcase}“,
:title => dealer.name)
end
clusterer = Clusterer.new(markers, :max_visible_markers => 15)
@map.overlay_init clusterer
end
YM4R
• http://thepochisuperstarmegashow.com/projects
Wait
I want more than just that!
Wait
I want more than just that!
• find_within(distance, options={})
• find_beyond(distance, options={})
• find_closest(options={})
• find_farthest(options={})
GeoKit
• IpGeocoder.geocode('12.215.42.19')
• # => @success=true, @street_address=nil, @country_code="US", @zip=nil, @lng=-88.4588,
@state="IL", @city="Sugar Grove", @provider="hostip", @lat=41.7696
before_save :find_in_google_maps
protected
def find_in_google_maps
location = GoogleGeocoder.geocode(“#{self.street_number} #{self.street_name},
#{self.suburb}, #{self.state},
#{self.postcode}, Australia”)
if location.success
self.lat = location.lat
self.lng = location.lng
else
self.lat = nil
self.lng = nil
end
end
end
GeoKit
You can now find dealers in your controller and add them to the map:
def find_a_dealer
@dealers = Dealer.find(:all, :order => “name ASC”)
@map = GMap.new(“map_div”)
@map.control_init(:large_map => true, :map_type => true)
@map.center_zoom_init([-28.99425, 132.03845], 4)
markers = Array.new
@dealers.each do |dealer|
markers << GMarker.new([dealer.lat, dealer.lng],
:info_window => “<strong>#{dealer.name}</strong><br />
#{dealer.street_number}, #{dealer.street_name.capitalize},<br />
#{dealer.suburb.capitalize}, #{dealer.state.upcase}, #{dealer.postcode}<br />
PH: #{dealer.phone_number}, #{dealer.suburb.upcase}, #{dealer.state.upcase}“,
:title => dealer.name)
end
update_dealer_map.rjs:
unless @location.blank?
page << @map.set_center(GLatLng.new(@location), 12)
end
GeoKit
script/plugin install svn://rubyforge.org/var/svn/geokit/trunk
http://geokit.rubyforge.org/
GeoKit
script/plugin install svn://rubyforge.org/var/svn/geokit/trunk
http://geokit.rubyforge.org/
YM4R
script/plugin install svn://rubyforge.org/var/svn/ym4r/Plugins/GM/trunk/ym4r_gm
http://thepochisuperstarmegashow.com/projects