google-map-static-image-generator 0.0.2 → 0.0.4
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 +4 -4
- data/google-map-static-image-generator.gemspec +24 -2
- data/lib/google_map_static_image/version.rb +1 -1
- data/lib/google_map_static_image.rb +19 -5
- metadata +22 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94db30aa974e4abbe4fe9833f7577378e503769b120dfd42d1644b93b1e15d26
|
|
4
|
+
data.tar.gz: fe476b2e80c1a01afef83ddd76f4ff09eeb0615f79a54f57a91d6c62eabc96bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5cd728f5319bee186a881cf57e84e4016bed2a09eb2d5a89561df684cbbc2859b71066d5c526c58655161c4e372b9e55cd39a36cc470981df93bbcc01dd5f06
|
|
7
|
+
data.tar.gz: 67d9b41b920561fe35a305a1945beff374106d34a7de970fd2b93762e32102aba32b40e4fffc5c4f7f4139289e3576767ced72b6a47de66977b77d5c4165496b
|
|
@@ -5,12 +5,34 @@ Gem::Specification.new do |spec|
|
|
|
5
5
|
spec.version = GoogleMapStaticImage::VERSION
|
|
6
6
|
spec.authors = ["Abhishek Sharma"]
|
|
7
7
|
spec.email = ["abhsss96@gmail.com"]
|
|
8
|
-
spec.summary = "Generate static map images
|
|
9
|
-
spec.description =
|
|
8
|
+
spec.summary = "Generate customizable static map images via the Google Maps Static API"
|
|
9
|
+
spec.description = <<~DESC
|
|
10
|
+
google-map-static-image-generator is a Ruby wrapper around the Google Maps Static
|
|
11
|
+
API that generates PNG map images on the fly — no JavaScript required.
|
|
12
|
+
|
|
13
|
+
Features:
|
|
14
|
+
- Add custom markers at any coordinates
|
|
15
|
+
- Draw paths with custom weight and colour
|
|
16
|
+
- Apply map styles (hide labels, change colours, etc.)
|
|
17
|
+
- Set center + zoom for marker-free maps
|
|
18
|
+
- Choose map type: roadmap, satellite, terrain, or hybrid
|
|
19
|
+
- Default 1024x1024 at scale 2 (retina-friendly)
|
|
20
|
+
- Raises GoogleMapStaticImage::ApiError on non-200 responses (invalid key, quota exceeded, etc.)
|
|
21
|
+
|
|
22
|
+
Useful for generating map thumbnails in emails, PDFs, admin dashboards, and anywhere
|
|
23
|
+
an interactive JavaScript map is not practical.
|
|
24
|
+
DESC
|
|
10
25
|
spec.homepage = "https://github.com/abhsss96/google-map-static-image-generator"
|
|
11
26
|
spec.license = "MIT"
|
|
12
27
|
spec.required_ruby_version = ">= 2.7"
|
|
13
28
|
|
|
29
|
+
spec.metadata = {
|
|
30
|
+
"homepage_uri" => "https://github.com/abhsss96/google-map-static-image-generator",
|
|
31
|
+
"source_code_uri" => "https://github.com/abhsss96/google-map-static-image-generator",
|
|
32
|
+
"bug_tracker_uri" => "https://github.com/abhsss96/google-map-static-image-generator/issues",
|
|
33
|
+
"changelog_uri" => "https://github.com/abhsss96/google-map-static-image-generator/releases"
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
spec.files = Dir["lib/**/*", "README.md", "*.gemspec"]
|
|
15
37
|
spec.require_paths = ["lib"]
|
|
16
38
|
|
|
@@ -3,20 +3,34 @@ require_relative "google_map_static_image/version"
|
|
|
3
3
|
|
|
4
4
|
class GoogleMapStaticImage
|
|
5
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
|
|
6
16
|
|
|
7
17
|
def get_response(api_key, markers, option = {})
|
|
8
18
|
query = {}
|
|
9
|
-
query[:
|
|
19
|
+
query[:key] = api_key
|
|
10
20
|
query[:size] = "1024x1024"
|
|
11
21
|
query[:scale] = 2
|
|
12
|
-
query[:
|
|
13
|
-
query[:
|
|
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?
|
|
14
27
|
unless option[:location].nil?
|
|
15
|
-
query[:path] = [query[:path], option[:location].map { |
|
|
28
|
+
query[:path] = [query[:path], option[:location].map { |_k, v| v.to_s }.join("|")].join("|")
|
|
16
29
|
end
|
|
17
|
-
query[:markers] = option[:markers].map { |val| val.join("|") }
|
|
30
|
+
query[:markers] = option[:markers].map { |val| val.join("|") } unless option[:markers].nil?
|
|
18
31
|
|
|
19
32
|
response = HTTParty.get(STATIC_MAP_URL, query: query)
|
|
33
|
+
raise ApiError.new(response.code, response.body) unless response.code == 200
|
|
20
34
|
response.parsed_response
|
|
21
35
|
end
|
|
22
36
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abhishek Sharma
|
|
@@ -52,8 +52,21 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '3.0'
|
|
55
|
-
description:
|
|
56
|
-
|
|
55
|
+
description: |
|
|
56
|
+
google-map-static-image-generator is a Ruby wrapper around the Google Maps Static
|
|
57
|
+
API that generates PNG map images on the fly — no JavaScript required.
|
|
58
|
+
|
|
59
|
+
Features:
|
|
60
|
+
- Add custom markers at any coordinates
|
|
61
|
+
- Draw paths with custom weight and colour
|
|
62
|
+
- Apply map styles (hide labels, change colours, etc.)
|
|
63
|
+
- Set center + zoom for marker-free maps
|
|
64
|
+
- Choose map type: roadmap, satellite, terrain, or hybrid
|
|
65
|
+
- Default 1024x1024 at scale 2 (retina-friendly)
|
|
66
|
+
- Raises GoogleMapStaticImage::ApiError on non-200 responses (invalid key, quota exceeded, etc.)
|
|
67
|
+
|
|
68
|
+
Useful for generating map thumbnails in emails, PDFs, admin dashboards, and anywhere
|
|
69
|
+
an interactive JavaScript map is not practical.
|
|
57
70
|
email:
|
|
58
71
|
- abhsss96@gmail.com
|
|
59
72
|
executables: []
|
|
@@ -67,7 +80,11 @@ files:
|
|
|
67
80
|
homepage: https://github.com/abhsss96/google-map-static-image-generator
|
|
68
81
|
licenses:
|
|
69
82
|
- MIT
|
|
70
|
-
metadata:
|
|
83
|
+
metadata:
|
|
84
|
+
homepage_uri: https://github.com/abhsss96/google-map-static-image-generator
|
|
85
|
+
source_code_uri: https://github.com/abhsss96/google-map-static-image-generator
|
|
86
|
+
bug_tracker_uri: https://github.com/abhsss96/google-map-static-image-generator/issues
|
|
87
|
+
changelog_uri: https://github.com/abhsss96/google-map-static-image-generator/releases
|
|
71
88
|
post_install_message:
|
|
72
89
|
rdoc_options: []
|
|
73
90
|
require_paths:
|
|
@@ -86,5 +103,5 @@ requirements: []
|
|
|
86
103
|
rubygems_version: 3.5.22
|
|
87
104
|
signing_key:
|
|
88
105
|
specification_version: 4
|
|
89
|
-
summary: Generate static map images
|
|
106
|
+
summary: Generate customizable static map images via the Google Maps Static API
|
|
90
107
|
test_files: []
|