google-map-static-image-generator 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 54f1aa08f6692b02e86d62878a435d883dcdfc96
4
- data.tar.gz: f6432f0c242a32f9693c1d1b53f3afc76548fcac
2
+ SHA256:
3
+ metadata.gz: 237094e6bc2d8572ccc0b6aec9683a40c10592c233ede43c3d29bfcd99d25be8
4
+ data.tar.gz: 9ac489db924458a8195803288c6e8a3c496d452b792a5313d14d085289b9f7b4
5
5
  SHA512:
6
- metadata.gz: 1fd8455b0f7cf5b56f6e810c29f042848001bf27096d47abebfa60525ad6905c54af217b558b9eb66c953bfbac10826013da2a0fec4cc272912ca88204215e67
7
- data.tar.gz: d3a6de89494052b03d991d63881fc16051d94284449d04d3ee0bc5ae73b0ae2fa781d612587c85f08d972f14beaaf38b61a5adf4c545edc2903ee3c4f9cd7374
6
+ metadata.gz: f3ecd4695ad402c2fef5c65d897d8dd043783f3b63707a56441836039d6e45a7c2b64c068428f2c25b112b231d6a5fb217aecc5c3c3ce7b38a17bef4825b32c3
7
+ data.tar.gz: 2a6226dd661996dabad1758070fc8c0ca3379941a6114a0882820af202474300a694e6bc2bbf16d59d5e5db11bb37463c2282dc5b3993afb2289254b1dd710ee
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # google-map-static-image-generator
2
+
3
+ A Ruby gem that wraps the [Google Maps Static API](https://developers.google.com/maps/documentation/maps-static/overview) to generate customizable static map images in Rails applications.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'google-map-static-image-generator'
11
+ ```
12
+
13
+ Then run:
14
+
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ map = GoogleMapStaticImage.new
23
+
24
+ response = map.get_response(
25
+ "YOUR_GOOGLE_API_KEY",
26
+ markers, # array of marker coordinate strings
27
+ style: { feature: "all", element: "labels", visibility: "off" },
28
+ path: { weight: 3, color: "blue" },
29
+ location: { lat: "48.8584", lng: "2.2945" },
30
+ markers: [["48.8584,2.2945"], ["48.8606,2.3376"]]
31
+ )
32
+ ```
33
+
34
+ The response is the raw parsed response from the Google Static Maps API — typically image binary data or a redirect URL depending on your usage.
35
+
36
+ ## Options
37
+
38
+ | Option | Description |
39
+ |--------|-------------|
40
+ | `style` | Map style rules as a hash (`key: value` pairs joined with `\|`) |
41
+ | `path` | Path styling options (weight, color, etc.) |
42
+ | `location` | Hash of `lat`/`lng` to append to the path |
43
+ | `markers` | Array of marker groups; each group is an array of coordinate strings |
44
+
45
+ The default image size is `1024x1024` at scale `2`.
46
+
47
+ ## Dependencies
48
+
49
+ - [httparty](https://github.com/jnunemaker/httparty)
@@ -0,0 +1,21 @@
1
+ require_relative "lib/google_map_static_image/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "google-map-static-image-generator"
5
+ spec.version = GoogleMapStaticImage::VERSION
6
+ spec.authors = ["Abhishek Sharma"]
7
+ spec.email = ["abhsss96@gmail.com"]
8
+ spec.summary = "Generate static map images using the Google Maps Static API"
9
+ spec.description = "Wraps the Google Maps Static API to generate customizable static map images with markers, paths, and styles."
10
+ spec.homepage = "https://github.com/abhsss96/google-map-static-image-generator"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = ">= 2.7"
13
+
14
+ spec.files = Dir["lib/**/*", "README.md", "*.gemspec"]
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_dependency "httparty", ">= 0.14"
18
+
19
+ spec.add_development_dependency "rspec", "~> 3.12"
20
+ spec.add_development_dependency "webmock", "~> 3.0"
21
+ end
@@ -0,0 +1,3 @@
1
+ class GoogleMapStaticImage
2
+ VERSION = "0.0.3"
3
+ end
@@ -1,25 +1,36 @@
1
+ require "httparty"
2
+ require_relative "google_map_static_image/version"
3
+
1
4
  class GoogleMapStaticImage
2
- require "httparty"
3
- require "debugger"
4
- def get_response(api_key,markers,option={})
5
-
6
-
7
- url = "https://maps.googleapis.com/maps/api/staticmap"
8
- url1= "http://192.168.0.19:3041"
9
-
10
- query = Hash.new
11
- query[:api_key] = api_key
12
- query[:size] = "1024x1024"
13
- query[:scale] = 2
14
- query[:style] = option[:style].map {|key,val| "#{key}:#{val}"}.join("|") unless option[:style].nil?
15
- query[:path] = option[:path].map {|key,val| "#{key}:#{val}"}.join("|") unless option[:path].nil?
16
- query[:path] = [query[:path],option[:location].map {|key,val| "#{val}"}.join("|")].join("|") unless option[:location].nil?
17
- query[:markers] = option[:markers].map { |val| val.join("|")} unless option[:markers].nil?
18
-
19
- response = HTTParty.get("#{url1}", :query=>query)
20
- response = HTTParty.get("#{url}", :query=>query)
21
- return response.parsed_response
5
+ STATIC_MAP_URL = "https://maps.googleapis.com/maps/api/staticmap"
6
+ VALID_MAP_TYPES = %w[roadmap satellite terrain hybrid].freeze
7
+
8
+ class ApiError < StandardError
9
+ attr_reader :status, :body
10
+ def initialize(status, body)
11
+ @status = status
12
+ @body = body
13
+ super("Google Maps Static API error #{status}: #{body}")
14
+ end
15
+ end
22
16
 
23
- end
17
+ def get_response(api_key, markers, option = {})
18
+ query = {}
19
+ query[:key] = api_key
20
+ query[:size] = "1024x1024"
21
+ query[:scale] = 2
22
+ query[:center] = option[:center] unless option[:center].nil?
23
+ query[:zoom] = option[:zoom] unless option[:zoom].nil?
24
+ query[:maptype] = option[:map_type] if VALID_MAP_TYPES.include?(option[:map_type].to_s)
25
+ query[:style] = option[:style].map { |k, v| "#{k}:#{v}" }.join("|") unless option[:style].nil?
26
+ query[:path] = option[:path].map { |k, v| "#{k}:#{v}" }.join("|") unless option[:path].nil?
27
+ unless option[:location].nil?
28
+ query[:path] = [query[:path], option[:location].map { |_k, v| v.to_s }.join("|")].join("|")
29
+ end
30
+ query[:markers] = option[:markers].map { |val| val.join("|") } unless option[:markers].nil?
24
31
 
32
+ response = HTTParty.get(STATIC_MAP_URL, query: query)
33
+ raise ApiError.new(response.code, response.body) unless response.code == 200
34
+ response.parsed_response
35
+ end
25
36
  end
metadata CHANGED
@@ -1,45 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-map-static-image-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhishek Sharma
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-13 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Gem to expand usage of google map static image api with rails
14
- email: abhishek.sharma@medma.in
11
+ date: 2026-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Wraps the Google Maps Static API to generate customizable static map
56
+ images with markers, paths, and styles.
57
+ email:
58
+ - abhsss96@gmail.com
15
59
  executables: []
16
60
  extensions: []
17
61
  extra_rdoc_files: []
18
62
  files:
63
+ - README.md
64
+ - google-map-static-image-generator.gemspec
19
65
  - lib/google_map_static_image.rb
20
- homepage:
66
+ - lib/google_map_static_image/version.rb
67
+ homepage: https://github.com/abhsss96/google-map-static-image-generator
21
68
  licenses:
22
- - NONE
69
+ - MIT
23
70
  metadata: {}
24
- post_install_message:
71
+ post_install_message:
25
72
  rdoc_options: []
26
73
  require_paths:
27
74
  - lib
28
75
  required_ruby_version: !ruby/object:Gem::Requirement
29
76
  requirements:
30
- - - '>='
77
+ - - ">="
31
78
  - !ruby/object:Gem::Version
32
- version: '0'
79
+ version: '2.7'
33
80
  required_rubygems_version: !ruby/object:Gem::Requirement
34
81
  requirements:
35
- - - '>='
82
+ - - ">="
36
83
  - !ruby/object:Gem::Version
37
84
  version: '0'
38
85
  requirements: []
39
- rubyforge_project:
40
- rubygems_version: 2.3.0
41
- signing_key:
86
+ rubygems_version: 3.5.22
87
+ signing_key:
42
88
  specification_version: 4
43
- summary: Hello! This is library to get the google map static image as file object
44
- with different params
89
+ summary: Generate static map images using the Google Maps Static API
45
90
  test_files: []