Class: BHM::GoogleMaps::StaticMap

Inherits:
Object
  • Object
show all
Defined in:
lib/bhm/google_maps/static_map.rb

Constant Summary collapse

URL_TEMPLATE =
"http://maps.google.com/maps/api/staticmap?%s"
COLOURS =
%w(red white green brown blue orange gray purple yellow black)
LABELS =
('A'..'Z').to_a

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ StaticMap

Returns a new instance of StaticMap.



8
9
10
11
12
13
14
15
16
# File 'lib/bhm/google_maps/static_map.rb', line 8

def initialize(options = {})
  @addresses = []
  @width, @height = options.fetch(:width, 540), options.fetch(:height, 400)
  @params = Hash.new.tap do |p|
    p[:sensor]  = false
    p[:size]    = "#{@width}x#{@height}"
    p[:maptype] = options.fetch(:type, "roadmap")
  end
end

Class Method Details

.for_address(address, opts = {}) ⇒ Object



29
30
31
32
33
# File 'lib/bhm/google_maps/static_map.rb', line 29

def self.for_address(address, opts = {})
  map = self.new(opts.reverse_merge(:zoom => 15))
  map << address
  map.to_url
end

.for_addresses(*addresses) ⇒ Object



35
36
37
38
39
# File 'lib/bhm/google_maps/static_map.rb', line 35

def self.for_addresses(*addresses)
  map = self.new(addresses.extract_options!)
  addresses.flatten.each { |a| map << a }
  map.to_url
end

Instance Method Details

#<<(address) ⇒ Object



18
19
20
# File 'lib/bhm/google_maps/static_map.rb', line 18

def <<(address)
  @addresses << address
end

#to_urlObject



22
23
24
25
26
27
# File 'lib/bhm/google_maps/static_map.rb', line 22

def to_url
  params = @params.to_param
  params << "&"
  params << build_marker_params
  URL_TEMPLATE % params
end