google_static_maps_helper 1.1.0 → 1.2.0
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.
- data/README.rdoc +38 -0
- data/VERSION +1 -1
- data/google_static_maps_helper.gemspec +4 -2
- data/lib/google_static_maps_helper.rb +10 -0
- data/lib/google_static_maps_helper/map.rb +5 -0
- data/lib/google_static_maps_helper/marker.rb +2 -2
- data/spec/google_static_maps_helper_spec.rb +51 -0
- data/spec/map_spec.rb +10 -4
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -2,6 +2,37 @@
|
|
2
2
|
|
3
3
|
This gem provides a simple interface to the Google Static Maps V2 API (http://code.google.com/apis/maps/documentation/staticmaps/)
|
4
4
|
|
5
|
+
|
6
|
+
= Installation
|
7
|
+
If you haven't already, add gemcutter as a gem source
|
8
|
+
[sudo] gem sources --add http://gemcutter.org
|
9
|
+
|
10
|
+
Then install this gem
|
11
|
+
[sudo] gem install google_static_maps_helper
|
12
|
+
|
13
|
+
|
14
|
+
= The easiest way of generating a Google Static Maps URL
|
15
|
+
|
16
|
+
GoogleStaticMapsHelper.url_for do
|
17
|
+
marker :lng => 1, :lat => 2
|
18
|
+
marker :lng => 3, :lat => 4
|
19
|
+
end
|
20
|
+
|
21
|
+
This will return the url for map with these markers. Place note that if you do use this approach you have to set key, size and sensor setting.
|
22
|
+
You do this by:
|
23
|
+
GoogleStaticMapsHelper.key = 'your google key'
|
24
|
+
GoogleStaticMapsHelper.size = '300x600'
|
25
|
+
GoogleStaticMapsHelper.sensor = false
|
26
|
+
|
27
|
+
If you are on Rails you can put it in your environment configuration file and while you are there you can add the following line inside the configuration block:
|
28
|
+
Rails::Initializer.run do |config|
|
29
|
+
config.gem 'google_static_maps_helper', :source => 'http://gemcutter.org'
|
30
|
+
...
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
= A bit more "low-level" approach instantiating objects yourself
|
35
|
+
|
5
36
|
== Marker
|
6
37
|
A marker object is, not surprisingly, representing a marker in the Google static map. It is pushed into the Map object and is used
|
7
38
|
to generate the URL for the static map. Markers which are of the same "type" (same color, label and size) are grouped together in the generated URL
|
@@ -45,9 +76,16 @@ Another thing you might want to do is to override the center point and zoom leve
|
|
45
76
|
:center => '1,2',
|
46
77
|
:zoom => 4)
|
47
78
|
|
79
|
+
|
80
|
+
|
48
81
|
== Paths
|
49
82
|
Paths are not yet supported.
|
50
83
|
|
84
|
+
|
85
|
+
== TODO
|
86
|
+
* Paths
|
87
|
+
* Ruby 1.9 support
|
88
|
+
|
51
89
|
== Copyright
|
52
90
|
|
53
91
|
Copyright (c) 2009 Thorbjørn Hermansen. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{google_static_maps_helper}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thorbj\303\270rn Hermansen"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-14}
|
13
13
|
s.description = %q{This gem provides a simple interface to the Google Static Maps V2 API.}
|
14
14
|
s.email = %q{thhermansen@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/google_static_maps_helper.rb",
|
28
28
|
"lib/google_static_maps_helper/map.rb",
|
29
29
|
"lib/google_static_maps_helper/marker.rb",
|
30
|
+
"spec/google_static_maps_helper_spec.rb",
|
30
31
|
"spec/map_spec.rb",
|
31
32
|
"spec/marker_spec.rb",
|
32
33
|
"spec/spec_helper.rb"
|
@@ -39,6 +40,7 @@ Gem::Specification.new do |s|
|
|
39
40
|
s.test_files = [
|
40
41
|
"spec/spec_helper.rb",
|
41
42
|
"spec/marker_spec.rb",
|
43
|
+
"spec/google_static_maps_helper_spec.rb",
|
42
44
|
"spec/map_spec.rb"
|
43
45
|
]
|
44
46
|
|
@@ -8,4 +8,14 @@ module GoogleStaticMapsHelper
|
|
8
8
|
class OptionMissing < ArgumentError; end # Raised when required options is not sent in during construction
|
9
9
|
class OptionNotExist < ArgumentError; end # Raised when incoming options include keys which is invalid
|
10
10
|
class BuildDataMissing < Exception; end # Raised when incoming options include keys which is invalid
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :key, :size, :sensor
|
14
|
+
|
15
|
+
def url_for(map_options = {}, &block)
|
16
|
+
map = Map.new({:key => key, :size => size, :sensor => sensor}.merge(map_options))
|
17
|
+
block.arity < 1 ? map.instance_eval(&block) : block.call(map)
|
18
|
+
map.url
|
19
|
+
end
|
20
|
+
end
|
11
21
|
end
|
@@ -44,9 +44,9 @@ module GoogleStaticMapsHelper
|
|
44
44
|
# Returns a string wich is what Google Static map is using to
|
45
45
|
# set the style on the marker. This ill include color, size and label
|
46
46
|
def options_to_url_params
|
47
|
-
params = DEFAULT_OPTIONS.keys.inject([]) do |params, attr|
|
47
|
+
params = DEFAULT_OPTIONS.keys.map(&:to_s).sort.inject([]) do |params, attr|
|
48
48
|
value = send(attr)
|
49
|
-
params << "#{attr}:#{value}" if value
|
49
|
+
params << "#{attr}:#{URI.escape(value)}" if value
|
50
50
|
params
|
51
51
|
end
|
52
52
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe GoogleStaticMapsHelper do
|
4
|
+
describe "Friendly DSL API" do
|
5
|
+
describe "url_for" do
|
6
|
+
before do
|
7
|
+
GoogleStaticMapsHelper.key = 'my_key'
|
8
|
+
GoogleStaticMapsHelper.size = '300x500'
|
9
|
+
GoogleStaticMapsHelper.sensor = false
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a responding method" do
|
13
|
+
GoogleStaticMapsHelper.respond_to?(:url_for).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be possible to add markers to map through a b block" do
|
17
|
+
out = GoogleStaticMapsHelper.url_for do
|
18
|
+
marker :lat => 1, :lng => 2
|
19
|
+
end
|
20
|
+
|
21
|
+
out.should include('markers=color:red|size:mid|1,2')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be possible to override the default map construction values" do
|
25
|
+
out = GoogleStaticMapsHelper.url_for(:size => '800x800') do
|
26
|
+
marker :lat => 1, :lng => 2
|
27
|
+
end
|
28
|
+
|
29
|
+
out.should include('size=800x800')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be possible to use inside a class, using attributes of that class" do
|
33
|
+
class TestingClass
|
34
|
+
attr_reader :location
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
@location = {:lat => 1, :lng => 5}
|
38
|
+
end
|
39
|
+
|
40
|
+
def url
|
41
|
+
GoogleStaticMapsHelper.url_for do |map|
|
42
|
+
map.marker location
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
TestingClass.new.url.should include('markers=color:red|size:mid|1,5')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/map_spec.rb
CHANGED
@@ -156,8 +156,8 @@ describe GoogleStaticMapsHelper::Map do
|
|
156
156
|
['key', 'MY_GOOGLE_KEY'],
|
157
157
|
['sensor', 'true'],
|
158
158
|
['size', '400x600'],
|
159
|
-
['markers', 'size:mid|
|
160
|
-
['markers', 'size:mid|
|
159
|
+
['markers', 'color:green|size:mid|6,5'],
|
160
|
+
['markers', 'color:red|size:mid|2,1']
|
161
161
|
].each do |pair|
|
162
162
|
key, value = pair
|
163
163
|
it "should have key: #{key} and value: #{value}" do
|
@@ -178,8 +178,8 @@ describe GoogleStaticMapsHelper::Map do
|
|
178
178
|
['key', 'MY_GOOGLE_KEY'],
|
179
179
|
['sensor', 'true'],
|
180
180
|
['size', '400x600'],
|
181
|
-
['markers', 'size:mid|
|
182
|
-
['markers', 'size:mid|
|
181
|
+
['markers', 'color:green|size:mid|6,5|8,7'],
|
182
|
+
['markers', 'color:red|size:mid|2,1|4,3']
|
183
183
|
].each do |pair|
|
184
184
|
key, value = pair
|
185
185
|
it "should have key: #{key} and value: #{value}" do
|
@@ -188,4 +188,10 @@ describe GoogleStaticMapsHelper::Map do
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
end
|
191
|
+
|
192
|
+
it "should provide a helper method named marker which will create a new marker and add it to the map" do
|
193
|
+
map = GoogleStaticMapsHelper::Map.new(@@require_options)
|
194
|
+
map.marker(:lat => 1, :lng => 2)
|
195
|
+
map.length.should eql(1)
|
196
|
+
end
|
191
197
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_static_maps_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Thorbj\xC3\xB8rn Hermansen"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-14 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/google_static_maps_helper.rb
|
43
43
|
- lib/google_static_maps_helper/map.rb
|
44
44
|
- lib/google_static_maps_helper/marker.rb
|
45
|
+
- spec/google_static_maps_helper_spec.rb
|
45
46
|
- spec/map_spec.rb
|
46
47
|
- spec/marker_spec.rb
|
47
48
|
- spec/spec_helper.rb
|
@@ -76,4 +77,5 @@ summary: This gem provides a simple interface to the Google Static Maps V2 API
|
|
76
77
|
test_files:
|
77
78
|
- spec/spec_helper.rb
|
78
79
|
- spec/marker_spec.rb
|
80
|
+
- spec/google_static_maps_helper_spec.rb
|
79
81
|
- spec/map_spec.rb
|