googlestaticmap 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff2ebb1801c05d4809f1747c82f079cbed2b7ccc
4
- data.tar.gz: 042aaceadc71f079c683b3d4cbb7fd3dc8c9db01
3
+ metadata.gz: 1ddc7e2e770498a9ac12d73e0d79cf954b4333c9
4
+ data.tar.gz: 6e9dfcd215d46cb14de2708959e0caa5fba8e194
5
5
  SHA512:
6
- metadata.gz: 2d4be157dc6dd3058897e5c1b5c51fb2ec8991dd8fadfcdcc30c38141a402286f76cb540643ca085eeda6bfb309c793b1f2edc570105a96842269029f439cd12
7
- data.tar.gz: 56d3a7f1461f6186321ba86e29497f883eb398017076e8202c6584d53d05b5ce2a10a7797b72ccfda692d14b7c439353da6d5ad3d07df3a6b45a172dffd31179
6
+ metadata.gz: 2aa7f214d79aa9c8d0b0042b5169ee964b1a34b5310e09c018c6d887af82885252a11634ec89cc71be1c1490c92228b6bf7df431887e6de85552e654bcbfc328
7
+ data.tar.gz: b4ec9c02c81f05483bab97f3e066e877dfcb2d73f9b83dfd3dd139a39b5a1d23377cdad69c939139da20cff40fd0576698ea666ebc7671caf94483b8cf2c8519
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.2.0 / 2014-03-03
2
+ * Added support for setting an API key for monitoring, and a client ID/private key for business customers (thanks forrest!)
3
+ * Changed to use maps.googleapis.com instead of maps.google.com (thanks nathany!)
4
+ * Explicitly added MIT licensing
5
+
1
6
  == 1.1.4 / 2013-07-04
2
7
  * Properly URL encoding the URLs, caused an issue when using URI.parse on generated URLs (thanks nathany!)
3
8
 
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # googlestaticmap gem
2
+
3
+ This gem is on Rubygems, simply type "gem install googlestaticmap" to install it.
4
+
5
+ Available on github at http://github.com/brentsowers1/googlestaticmap
6
+
7
+ Class for generating URLs for and downloading static maps from the Google Maps
8
+ Static API service. GoogleStaticMap is the main class to use, instantiate it,
9
+ set the attributes to what you want, and call url on the instance to get the
10
+ URL to download the map from. You can also call get_map to actually
11
+ download the map from Google, return the bytes, and optionally write the
12
+ image to a file.
13
+
14
+ ## Examples:
15
+
16
+ Get a simple static map centered at Washington, DC, with the default size
17
+ (500 x 350), zoomed to level 11. image will be the binary data of the map
18
+
19
+ require 'googlestaticmap'
20
+ map = GoogleStaticMap.new(:zoom => 11, :center => MapLocation.new(:address => "Washington, DC"))
21
+ image = map.get_map
22
+
23
+ Get the URL of the image described in the previous example, so you can insert
24
+ this URL as the src of an img element on an HTML page
25
+
26
+ require 'googlestaticmap'
27
+ map = GoogleStaticMap.new(:zoom => 11, :center => MapLocation.new(:address => "Washington, DC"))
28
+ image_url = map.url(:auto)
29
+
30
+ Get a map with blue markers at the White House and the Supreme Court, zoomed
31
+ the closest that the map can be with both markers visible, at the default
32
+ size. image will be the binary data of the map
33
+
34
+ require 'googlestaticmap'
35
+ map = GoogleStaticMap.new
36
+ map.markers << MapMarker.new(:color => "blue", :location => MapLocation.new(:address => "1600 Pennsylvania Ave., Washington, DC"))
37
+ map.markers << MapMarker.new(:color => "blue", :location => MapLocation.new(:address => "1 1st Street Northeast, Washington, DC"))
38
+ image = map.get_map
39
+
40
+ Get a GIF satellite map, with a size of 640 x 480, with a
41
+ semi transparent green box drawn around a set of 4 coordinates, with the box
42
+ outline solid, centered at the middle of the box, written out to the file
43
+ map.gif:
44
+
45
+ require 'googlestaticmap'
46
+ map = GoogleStaticMap.new(:maptype => "satellite", :format => "gif", :width => 640, :height => 480)
47
+ poly = MapPolygon.new(:color => "0x00FF00FF", :fillcolor => "0x00FF0060")
48
+ poly.points << MapLocation.new(:latitude => 38.8, :longitude => -77.5)
49
+ poly.points << MapLocation.new(:latitude => 38.8, :longitude => -76.9)
50
+ poly.points << MapLocation.new(:latitude => 39.2, :longitude => -76.9)
51
+ poly.points << MapLocation.new(:latitude => 39.2, :longitude => -77.5)
52
+ poly.points << MapLocation.new(:latitude => 38.8, :longitude => -77.5)
53
+ map.paths << poly
54
+ map.get_map("map.gif")
55
+
56
+ If you're working behind a proxy, create the map object this way:
57
+
58
+ map = GoogleStaticMap.new(:proxy_address=>'my.proxy.host', :proxy_port=>8080, :width => 640, :height => 480)
59
+
60
+ If you have a public API key for tracking usage (https://developers.google.com/maps/documentation/staticmaps/#api_key):
61
+
62
+ map = GoogleStaticMap.new(:api_key => "my_api_key")
63
+
64
+ If you are a Maps For Businesses customer with a client ID and private key (https://developers.google.com/maps/documentation/business/webservices/#client_id)
65
+ (note that you cannot set an api_key if you want to use client_id and private_key):
66
+
67
+ map = GoogleStaticMap.new(:client_id => "my_client_id", :private_key => "my_private_key")
68
+
69
+ ## Compatibility
70
+
71
+ This has been tested and is working with Ruby 1.8.7, 1.9.3, 2.0.0, and 2.1.1, and JRuby 1.7.11.
72
+
73
+ ## Author
74
+
75
+ Brent Sowers (mailto:brent@coordinatecommons.com)
76
+
77
+ ## Feedback
78
+
79
+ To post comments about this gem, go to my blog posting at http://www.brentsowers.com/2010/08/gem-for-getting-google-static-maps.html. Contributions are also welcome! Fork the repo and issue a pull request, and I'll review it.
80
+
81
+ ## License
82
+
83
+ googlestaticmap is released under the [MIT License](http://www.opensource.org/licenses/MIT). You're free to do whatever you want with this.
84
+
85
+
@@ -1,61 +1,9 @@
1
- # = googlestaticmap gem
2
- #
3
- # This gem is on Rubygems, simply type "gem install googlestaticmap" to install it.
4
- #
5
- # Available on github at http://github.com/brentsowers1/googlestaticmap
6
- #
7
- # Class for generating URLs for and downloading static maps from the Google Maps
8
- # Static API service. GoogleStaticMap is the main class to use, instantiate it,
9
- # set the attributes to what you want, and call full_url on the instance to get
10
- # the URL to download the map from. You can also call get_map to actually
11
- # download the map from Google, return the bytes, and optionally write the
12
- # image to a file.
13
- #
14
- # Examples:
15
- #
16
- # Get a simple static map centered at Washington, DC, with the default size
17
- # (500 x 350), zoomed to level 11
18
- # map = GoogleStaticMap.new(:zoom => 11, :center => MapLocation.new(:address => "Washington, DC"))
19
- # image = map.get_map
20
- #
21
- # Get the URL of the image described in the previous example, so you can insert
22
- # this URL as the src of an img element on an HTML page
23
- # require 'googlestaticmap'
24
- # map = GoogleStaticMap.new(:zoom => 11, :center => MapLocation.new(:address => "Washington, DC"))
25
- # image_url = map.url(:auto)
26
- #
27
- # Get a map with blue markers at the White House and the Supreme Court, zoomed
28
- # the closest that the map can be with both markers visible, at the default
29
- # size.
30
- # map = GoogleStaticMap.new
31
- # map.markers << MapMarker.new(:color => "blue", :location => MapLocation.new(:address => "1600 Pennsylvania Ave., Washington, DC"))
32
- # map.markers << MapMarker.new(:color => "blue", :location => MapLocation.new(:address => "1 1st Street Northeast, Washington, DC"))
33
- # image = map.get_map
34
- #
35
- # Get a GIF satellite map, with a size of 640 x 480, with a
36
- # semi transparent green box drawn around a set of 4 coordinates, with the box
37
- # outline solid, centered at the middle of the box, written out to the file
38
- # map.gif:
39
- # map = GoogleStaticMap.new(:maptype => "satellite", :format => "gif", :width => 640, :height => 480)
40
- # poly = MapPolygon.new(:color => "0x00FF00FF", :fillcolor => "0x00FF0060")
41
- # poly.points << MapLocation.new(:latitude => 38.8, :longitude => -77.5)
42
- # poly.points << MapLocation.new(:latitude => 38.8, :longitude => -76.9)
43
- # poly.points << MapLocation.new(:latitude => 39.2, :longitude => -76.9)
44
- # poly.points << MapLocation.new(:latitude => 39.2, :longitude => -77.5)
45
- # poly.points << MapLocation.new(:latitude => 38.8, :longitude => -77.5)
46
- # map.paths << poly
47
- # map.get_map("map.gif")
48
- #
49
- # If you're working behind a proxy, create the map object this way:
50
- # map = GoogleStaticMap.new(:proxy_address=>'my.proxy.host', :proxy_port=>8080, :width => 640, :height => 480)
51
- #
52
- # Author:: Brent Sowers (mailto:brent@coordinatecommons.com)
53
- # License:: You're free to do whatever you want with this
54
- #
55
- # To post comments about this gem, go to my blog posting at
56
- # http://www.brentsowers.com/2010/08/gem-for-getting-google-static-maps.html
1
+ # Main file for the googlestaticmap gem. See README.md for a full desciption with examples, licensing, contact
2
+ # info, etc.
57
3
 
58
4
  require 'cgi'
5
+ require 'base64'
6
+ require 'openssl'
59
7
  require 'net/http'
60
8
  require 'net/https' if RUBY_VERSION < "1.9"
61
9
  require File.dirname(__FILE__) + '/googlestaticmap_helper'
@@ -118,11 +66,22 @@ class GoogleStaticMap
118
66
  # If proxy_address is set, set this to the port of the proxy server
119
67
  attr_accessor :proxy_port
120
68
 
69
+ # API Key - see https://developers.google.com/maps/documentation/staticmaps/#api_key for details
70
+ # Note that if this is set, the client ID and private key will be ignored if set
71
+ attr_accessor :api_key
72
+
73
+ # ClientId/PrivateKey for business customers -
74
+ # see https://developers.google.com/maps/documentation/business/webservices/auth#generating_valid_signatures for details
75
+ # These will be ignored if api_key is set
76
+ attr_accessor :client_id
77
+ attr_accessor :private_key
78
+
121
79
  # Takes an optional hash of attributes
122
80
  def initialize(attrs={})
123
81
  defaults = {:width => 500, :height => 350, :markers => [],
124
82
  :sensor => false, :maptype => "roadmap", :paths => [],
125
- :proxy_port => nil, :proxy_address => nil,}
83
+ :proxy_port => nil, :proxy_address => nil, :api_key => nil,
84
+ :client_id => nil, :private_key => nil}
126
85
 
127
86
  attributes = defaults.merge(attrs)
128
87
  attributes.each {|k,v| self.send("#{k}=".to_sym,v)}
@@ -130,9 +89,9 @@ class GoogleStaticMap
130
89
 
131
90
  # Returns the full URL to retrieve this static map. You can use this as the
132
91
  # src for an img to display an image directly on a web page
133
- # Example - "http://maps.google.com/maps/api/staticmap?params..."
92
+ # Example - "http://maps.googleapis.com/maps/api/staticmap?params..."
134
93
  # +protocol+ can be 'http', 'https' or :auto. Specifying :auto will not return
135
- # a protocol in the URL ("//maps.google.com/..."), allowing the browser to
94
+ # a protocol in the URL ("//maps.googleapis.com/..."), allowing the browser to
136
95
  # select the appropriate protocol (if the page is loaded with https, it will
137
96
  # use https). Defaults to http
138
97
  def url(protocol='http')
@@ -142,22 +101,30 @@ class GoogleStaticMap
142
101
  protocol = 'http' unless protocol == 'http' || protocol == 'https' ||
143
102
  protocol == :auto
144
103
  protocol = protocol == :auto ? '' : protocol + ":"
145
- u = "#{protocol}//maps.google.com/maps/api/staticmap?"
104
+ base = "#{protocol}//maps.googleapis.com"
105
+ path = "/maps/api/staticmap?"
146
106
  attrs = GoogleStaticMapHelpers.safe_instance_variables(self,
147
107
  ["markers", "paths", "width", "height", "center",
148
- "proxy_address", "proxy_port"],
108
+ "proxy_address", "proxy_port", "api_key", "client_id",
109
+ "private_key"],
149
110
  :cgi_escape_values => true).to_a
150
111
  attrs << ["size", "#{@width}x#{@height}"] if @width && @height
151
- markers.each {|m| attrs << ["markers",m.to_s] }
152
- paths.each {|p| attrs << ["path",p.to_s] }
153
- attrs << ["center", center.to_s] if !center.nil?
154
- u << attrs.collect {|attr| "#{attr[0]}=#{attr[1]}"}.join("&")
112
+ @markers.each {|m| attrs << ["markers",m.to_s] }
113
+ @paths.each {|p| attrs << ["path",p.to_s] }
114
+ attrs << ["center", @center.to_s] if !@center.nil?
115
+ attrs << ["key", @api_key] if !@api_key.nil?
116
+ attrs << ["client", @client_id] if @api_key.nil? && !@client_id.nil? && !@private_key.nil?
117
+ path << attrs.collect {|attr| "#{attr[0]}=#{attr[1]}"}.join("&")
118
+ if @api_key.nil? && !@client_id.nil? && !@private_key.nil?
119
+ path << "&signature=" << sign(path)
120
+ end
121
+ base + path
155
122
  end
156
123
 
157
- # Returns the URL to retrieve the map, relative to http://maps.google.com
124
+ # Returns the URL to retrieve the map, relative to http://maps.googleapis.com
158
125
  # Example - "/maps/api/staticmap?params..."
159
126
  def relative_url(protocol='http')
160
- url(protocol).gsub(/[^\/]*\/\/maps\.google\.com/, "")
127
+ url(protocol).gsub(/[^\/]*\/\/maps\.googleapis\.com/, "")
161
128
  end
162
129
 
163
130
 
@@ -172,7 +139,7 @@ class GoogleStaticMap
172
139
  def get_map(output_file=nil, protocol='http')
173
140
  protocol = 'http' unless protocol == 'http' || protocol == 'https'
174
141
  port = protocol == 'https' ? 443 : 80
175
- http = Net::HTTP.Proxy(@proxy_address,@proxy_port).new("maps.google.com", port)
142
+ http = Net::HTTP.Proxy(@proxy_address,@proxy_port).new("maps.googleapis.com", port)
176
143
  http.use_ssl = protocol == 'https'
177
144
 
178
145
  resp = http.get2(relative_url(protocol))
@@ -189,6 +156,25 @@ class GoogleStaticMap
189
156
  end
190
157
  end
191
158
  end
159
+
160
+ private
161
+
162
+ # signing code is grabbed from https://github.com/alexreisner/geocoder
163
+ def sign(path)
164
+ raw_private_key = url_safe_base64_decode(@private_key)
165
+ digest = OpenSSL::Digest.new('sha1')
166
+ raw_signature = OpenSSL::HMAC.digest(digest, raw_private_key, path)
167
+ url_safe_base64_encode(raw_signature)
168
+ end
169
+
170
+ def url_safe_base64_decode(base64_string)
171
+ Base64.decode64(base64_string.tr('-_', '+/'))
172
+ end
173
+
174
+ def url_safe_base64_encode(raw)
175
+ Base64.encode64(raw).tr('+/', '-_').strip
176
+ end
177
+
192
178
  end
193
179
 
194
180
  # Container class for a location on the map. Set either a latitude and
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'cgi'
4
4
  require 'net/http'
5
- require 'mocha'
5
+ require 'mocha/setup'
6
6
  require File.dirname(__FILE__) + '/../lib/googlestaticmap'
7
7
 
8
8
  class MockSuccess < Net::HTTPSuccess #:nodoc: all
@@ -67,13 +67,17 @@ class GoogleStaticMapTest < Test::Unit::TestCase #:nodoc: all
67
67
  assert u.include?("maptype=hybrid")
68
68
  assert u.include?("scale=2")
69
69
  assert u.include?("asdf")
70
- assert u.include?("http://maps.google.com")
71
- assert u.include?("color:0x00FF00FF#{MAP_SEPARATOR}fillcolor:0x00FF0060#{MAP_SEPARATOR}38.8,-77.5#{MAP_SEPARATOR}38.8,-76.9#{MAP_SEPARATOR}39.2,-76.9#{MAP_SEPARATOR}39.2,-77.5#{MAP_SEPARATOR}38.8,-77.5"), "Polygon not in URL"
70
+ assert u.include?("http://maps.googleapis.com")
71
+ assert u.include?("color:0x00FF00FF")
72
+ assert u.include?("fillcolor:0x00FF0060")
73
+ assert u.include?("38.8,-77.5#{MAP_SEPARATOR}38.8,-76.9#{MAP_SEPARATOR}39.2,-76.9#{MAP_SEPARATOR}39.2,-77.5#{MAP_SEPARATOR}38.8,-77.5"), "Polygon not in URL - #{u}"
72
74
  assert u.include?("Washington%2C+DC")
75
+ assert !u.include?("key"), "API included when it shouldn't be"
76
+ assert !u.include?("client"), "Client included when it shouldn't be"
73
77
 
74
78
  f = nil
75
79
  assert_nothing_raised {f = g.relative_url}
76
- assert !f.include?("http://maps.google.com")
80
+ assert !f.include?("http://maps.googleapis.com")
77
81
  end
78
82
 
79
83
  def test_url_auto
@@ -81,10 +85,10 @@ class GoogleStaticMapTest < Test::Unit::TestCase #:nodoc: all
81
85
  u = nil
82
86
  assert_nothing_raised { u = g.url(:auto) }
83
87
  assert_equal 7, u.split("&").length, u
84
- assert u =~ /^\/\/maps.google.com/, u
88
+ assert u =~ /^\/\/maps.googleapis.com/, u
85
89
  f = nil
86
90
  assert_nothing_raised {f = g.relative_url}
87
- assert_no_match /^\/\/maps.google.com/, f
91
+ assert_no_match /^\/\/maps.googleapis.com/, f
88
92
  end
89
93
 
90
94
  def test_url_https
@@ -92,10 +96,44 @@ class GoogleStaticMapTest < Test::Unit::TestCase #:nodoc: all
92
96
  u = nil
93
97
  assert_nothing_raised { u = g.url('https') }
94
98
  assert_equal 7, u.split("&").length, u
95
- assert u =~ /^https:\/\/maps.google.com/
99
+ assert u =~ /^https:\/\/maps.googleapis.com/
96
100
  f = nil
97
101
  assert_nothing_raised {f = g.relative_url}
98
- assert_no_match /^https:\/\/maps.google.com/, f
102
+ assert_no_match /^https:\/\/maps.googleapis.com/, f
103
+ end
104
+
105
+ def test_url_api_key
106
+ g = default_map
107
+ g.api_key = "asdfapikey"
108
+ u = nil
109
+ assert_nothing_raised { u = g.url }
110
+ assert_equal 8, u.split("&").length, u
111
+ assert u.include?("key=asdfapikey"), u
112
+ assert !u.include?("client"), u
113
+ assert !u.include?("signature"), u
114
+ end
115
+
116
+ def test_url_for_business
117
+ g = default_map
118
+ g.client_id = "asdfclientid"
119
+ g.private_key = "asdfprivatekey"
120
+ u = nil
121
+ assert_nothing_raised { u = g.url }
122
+ assert_equal 9, u.split("&").length, u
123
+ assert u.include?("signature="), u
124
+ assert u.include?("client=asdfclientid"), u
125
+ assert !u.include?("key="), u
126
+ end
127
+
128
+ def test_url_for_business_no_key
129
+ g = default_map
130
+ g.client_id = "asdfclientid"
131
+ u = nil
132
+ assert_nothing_raised { u = g.url }
133
+ assert_equal 7, u.split("&").length, u
134
+ assert !u.include?("signature=")
135
+ assert !u.include?("client=asdfclientid")
136
+ assert !u.include?("key=")
99
137
  end
100
138
 
101
139
  def test_get_map_success_no_file_http
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googlestaticmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Sowers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-04 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easily retrieve single PNG, GIF, or JPG map images from Google with your
14
14
  own custom markers and paths using the Static Maps API service with this gem. Simply
@@ -18,20 +18,21 @@ email: brent@coordinatecommons.com
18
18
  executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files:
21
- - README
21
+ - README.md
22
22
  - History.txt
23
23
  files:
24
+ - History.txt
25
+ - README.md
24
26
  - lib/googlestaticmap.rb
25
27
  - lib/googlestaticmap_helper.rb
26
- - test/tc_map_path_and_polygon.rb
27
- - test/tc_map_location.rb
28
28
  - test/tc_google_static_map.rb
29
29
  - test/tc_helper.rb
30
+ - test/tc_map_location.rb
30
31
  - test/tc_map_marker.rb
31
- - README
32
- - History.txt
32
+ - test/tc_map_path_and_polygon.rb
33
33
  homepage: http://www.coordinatecommons.com/googlestaticmap/
34
- licenses: []
34
+ licenses:
35
+ - MIT
35
36
  metadata: {}
36
37
  post_install_message:
37
38
  rdoc_options: []
@@ -39,17 +40,17 @@ require_paths:
39
40
  - lib
40
41
  required_ruby_version: !ruby/object:Gem::Requirement
41
42
  requirements:
42
- - - '>='
43
+ - - ">="
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
46
  required_rubygems_version: !ruby/object:Gem::Requirement
46
47
  requirements:
47
- - - '>='
48
+ - - ">="
48
49
  - !ruby/object:Gem::Version
49
50
  version: '0'
50
51
  requirements: []
51
52
  rubyforge_project:
52
- rubygems_version: 2.0.3
53
+ rubygems_version: 2.2.2
53
54
  signing_key:
54
55
  specification_version: 4
55
56
  summary: Class for retrieving maps from the Google Maps Static API service
data/README DELETED
@@ -1,60 +0,0 @@
1
- = googlestaticmap gem
2
-
3
- This gem is on Rubygems, simply type "gem install googlestaticmap" to install it.
4
-
5
- Available on github at http://github.com/brentsowers1/googlestaticmap
6
-
7
- Class for generating URLs for and downloading static maps from the Google Maps
8
- Static API service. GoogleStaticMap is the main class to use, instantiate it,
9
- set the attributes to what you want, and call url on the instance to get the
10
- URL to download the map from. You can also call get_map to actually
11
- download the map from Google, return the bytes, and optionally write the
12
- image to a file.
13
-
14
- == Examples:
15
-
16
- Get a simple static map centered at Washington, DC, with the default size
17
- (500 x 350), zoomed to level 11. image will be the binary data of the map
18
- require 'googlestaticmap'
19
- map = GoogleStaticMap.new(:zoom => 11, :center => MapLocation.new(:address => "Washington, DC"))
20
- image = map.get_map
21
-
22
- Get the URL of the image described in the previous example, so you can insert
23
- this URL as the src of an img element on an HTML page
24
- require 'googlestaticmap'
25
- map = GoogleStaticMap.new(:zoom => 11, :center => MapLocation.new(:address => "Washington, DC"))
26
- image_url = map.url(:auto)
27
-
28
- Get a map with blue markers at the White House and the Supreme Court, zoomed
29
- the closest that the map can be with both markers visible, at the default
30
- size. image will be the binary data of the map
31
- require 'googlestaticmap'
32
- map = GoogleStaticMap.new
33
- map.markers << MapMarker.new(:color => "blue", :location => MapLocation.new(:address => "1600 Pennsylvania Ave., Washington, DC"))
34
- map.markers << MapMarker.new(:color => "blue", :location => MapLocation.new(:address => "1 1st Street Northeast, Washington, DC"))
35
- image = map.get_map
36
-
37
- Get a GIF satellite map, with a size of 640 x 480, with a
38
- semi transparent green box drawn around a set of 4 coordinates, with the box
39
- outline solid, centered at the middle of the box, written out to the file
40
- map.gif:
41
- require 'googlestaticmap'
42
- map = GoogleStaticMap.new(:maptype => "satellite", :format => "gif", :width => 640, :height => 480)
43
- poly = MapPolygon.new(:color => "0x00FF00FF", :fillcolor => "0x00FF0060")
44
- poly.points << MapLocation.new(:latitude => 38.8, :longitude => -77.5)
45
- poly.points << MapLocation.new(:latitude => 38.8, :longitude => -76.9)
46
- poly.points << MapLocation.new(:latitude => 39.2, :longitude => -76.9)
47
- poly.points << MapLocation.new(:latitude => 39.2, :longitude => -77.5)
48
- poly.points << MapLocation.new(:latitude => 38.8, :longitude => -77.5)
49
- map.paths << poly
50
- map.get_map("map.gif")
51
-
52
- If you're working behind a proxy, create the map object this way:
53
- map = GoogleStaticMap.new(:proxy_address=>'my.proxy.host', :proxy_port=>8080, :width => 640, :height => 480)
54
-
55
-
56
- Author:: Brent Sowers (mailto:brent@coordinatecommons.com)
57
- License:: You're free to do whatever you want with this
58
-
59
- To post comments about this gem, go to my blog posting at
60
- http://www.brentsowers.com/2010/08/gem-for-getting-google-static-maps.html