Class: GoogleMapStaticImage

Inherits:
Object
  • Object
show all
Defined in:
lib/google_map_static_image.rb,
lib/google_map_static_image/version.rb

Constant Summary collapse

STATIC_MAP_URL =
"https://maps.googleapis.com/maps/api/staticmap"
VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#get_response(api_key, markers, option = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/google_map_static_image.rb', line 7

def get_response(api_key, markers, option = {})
  query = {}
  query[:api_key] = api_key
  query[:size]    = "1024x1024"
  query[:scale]   = 2
  query[:style]   = option[:style].map { |key, val| "#{key}:#{val}" }.join("|") unless option[:style].nil?
  query[:path]    = option[:path].map { |key, val| "#{key}:#{val}" }.join("|") unless option[:path].nil?
  unless option[:location].nil?
    query[:path] = [query[:path], option[:location].map { |_key, val| val.to_s }.join("|")].join("|")
  end
  query[:markers] = option[:markers].map { |val| val.join("|") } unless option[:markers].nil?

  response = HTTParty.get(STATIC_MAP_URL, query: query)
  response.parsed_response
end