Class: GoogleMaps::Services::StaticMap
- Inherits:
-
Object
- Object
- GoogleMaps::Services::StaticMap
- Defined in:
- lib/googlemaps/services/staticmap.rb
Overview
Performs requests to the Google Static Map API.
Instance Attribute Summary collapse
-
#client ⇒ Symbol
The HTTP client.
Instance Method Summary collapse
-
#initialize(client) ⇒ StaticMap
constructor
A new instance of StaticMap.
-
#query(size:, center: nil, zoom: nil, scale: 1, format: "png", maptype: "roadmap", language: nil, region: nil, markers: nil, path: nil, visible: nil, style: nil) ⇒ Hash
Get the static map image.
Constructor Details
#initialize(client) ⇒ StaticMap
Returns a new instance of StaticMap.
25 26 27 |
# File 'lib/googlemaps/services/staticmap.rb', line 25 def initialize(client) self.client = client end |
Instance Attribute Details
#client ⇒ Symbol
Returns The HTTP client.
23 24 25 |
# File 'lib/googlemaps/services/staticmap.rb', line 23 def client @client end |
Instance Method Details
#query(size:, center: nil, zoom: nil, scale: 1, format: "png", maptype: "roadmap", language: nil, region: nil, markers: nil, path: nil, visible: nil, style: nil) ⇒ Hash
Get the static map image.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/googlemaps/services/staticmap.rb', line 45 def query(size:, center: nil, zoom: nil, scale: 1, format: "png", maptype: "roadmap", language: nil, region: nil, markers: nil, path: nil, visible: nil, style: nil) params = { 'size' => Convert.rectangular_dimensions(size) } if markers params['markers'] = markers else raise StandardError, "both center and zoom are required if markers not present." unless (center && zoom) params['center'] = Convert.to_latlng(center) params['zoom'] = zoom end if scale != 1 raise StandardError, "invalid scale value." unless Constants::ALLOWED_SCALES.include? scale params['scale'] = scale end if format != "png" raise StandardError, "invalid image format." unless Constants::SUPPORTED_IMG_FORMATS.include? format params['format'] = format end if maptype != "roadmap" raise StandardError, "invalid maptype value." unless Constants::SUPPORTED_MAP_TYPES.include? maptype params['maptype'] = maptype end if language params['language'] = language end if region params['region'] = region end if path params['path'] = path end if visible params['visible'] = visible end if style params['style'] = style end self.client.request(url: "/maps/api/staticmap", params: params) end |