google-maps 3.0.4 → 3.0.5
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/.travis.yml +1 -1
- data/README.md +15 -0
- data/lib/google_maps/location.rb +15 -3
- data/lib/google_maps/place.rb +16 -0
- data/lib/google_maps/version.rb +1 -1
- data/spec/google_maps_spec.rb +19 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4daaeaea85dad0ecfd2ed66cac2509ec167f3529e95d9d219818544ef097c28
|
4
|
+
data.tar.gz: 197b0d42d71e4b6c536da5c5a1a828640e377cd052648fe6f53b3a5d1458a21e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20c66bd8480bb08e67e9926a493944a76d04a34086b6ad313eafcb6efbbbe3d2b8f77d69be10c1da82e4cdaf93dc81e3becf6bb9c586e863819cfc82e3469041
|
7
|
+
data.tar.gz: 531cc41b79b18c66e6854c49b4fb77cfd91e6440f88ab29c8c8ebb3255a27f16e7431525b2ebef0638b8ee3daea058877f3aeb3152a7a9bfc491c7c283cd36e0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -183,6 +183,9 @@ AVOID = [
|
|
183
183
|
|
184
184
|
place = Google::Maps.place("ChIJVXealLU_xkcRja_At0z9AGY")
|
185
185
|
|
186
|
+
place.place_id
|
187
|
+
#=> "ChIJVXealLU_xkcRja_At0z9AGY"
|
188
|
+
|
186
189
|
place.latitude
|
187
190
|
#=> "52.3679843"
|
188
191
|
|
@@ -191,6 +194,18 @@ AVOID = [
|
|
191
194
|
|
192
195
|
place.address
|
193
196
|
#=> "Amsterdam, Nederland"
|
197
|
+
|
198
|
+
place.name
|
199
|
+
#=> "Amsterdam"
|
200
|
+
|
201
|
+
place.photos
|
202
|
+
#<Google::Maps::Result height, html_attribution[], photo_reference, width>
|
203
|
+
|
204
|
+
place.website
|
205
|
+
#=> "http://www.amsterdam.nl/"
|
206
|
+
|
207
|
+
place.url
|
208
|
+
#=> "https://maps.google.com/?q=Amsterdam,+Netherlands"
|
194
209
|
```
|
195
210
|
|
196
211
|
### Geocode
|
data/lib/google_maps/location.rb
CHANGED
@@ -5,13 +5,14 @@ require File.expand_path('api', __dir__)
|
|
5
5
|
module Google
|
6
6
|
module Maps
|
7
7
|
class Location
|
8
|
-
attr_reader :address, :latitude, :longitude
|
8
|
+
attr_reader :address, :latitude, :longitude, :components
|
9
9
|
alias to_s address
|
10
10
|
|
11
|
-
def initialize(address, latitude, longitude)
|
11
|
+
def initialize(address, latitude, longitude, components = {})
|
12
12
|
@address = address
|
13
13
|
@latitude = latitude
|
14
14
|
@longitude = longitude
|
15
|
+
@components = components
|
15
16
|
end
|
16
17
|
|
17
18
|
def lat_lng
|
@@ -25,10 +26,21 @@ module Google
|
|
25
26
|
Location.new(
|
26
27
|
result.formatted_address,
|
27
28
|
result.geometry.location.lat,
|
28
|
-
result.geometry.location.lng
|
29
|
+
result.geometry.location.lng,
|
30
|
+
format_components(result.address_components)
|
29
31
|
)
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
35
|
+
def self.format_components(address_components)
|
36
|
+
address_components.each_with_object({}) do |v, acc|
|
37
|
+
types = v['types']
|
38
|
+
types.each do |t|
|
39
|
+
acc[t] ||= []
|
40
|
+
acc[t] << v['long_name']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
32
44
|
end
|
33
45
|
end
|
34
46
|
end
|
data/lib/google_maps/place.rb
CHANGED
@@ -53,6 +53,22 @@ module Google
|
|
53
53
|
@data.place_id
|
54
54
|
end
|
55
55
|
|
56
|
+
def photos
|
57
|
+
@data.photos
|
58
|
+
end
|
59
|
+
|
60
|
+
def url
|
61
|
+
@data.url
|
62
|
+
end
|
63
|
+
|
64
|
+
def name
|
65
|
+
@data.name
|
66
|
+
end
|
67
|
+
|
68
|
+
def website
|
69
|
+
@data.website
|
70
|
+
end
|
71
|
+
|
56
72
|
def address
|
57
73
|
@data.formatted_address
|
58
74
|
end
|
data/lib/google_maps/version.rb
CHANGED
data/spec/google_maps_spec.rb
CHANGED
@@ -52,6 +52,25 @@ describe Google::Maps do
|
|
52
52
|
expect(location.lat_lng).to eq([52.3564490, 4.95568890])
|
53
53
|
end
|
54
54
|
|
55
|
+
it 'should extract all components for an address' do
|
56
|
+
stub_response('geocoder/science-park-400-amsterdam-en.json')
|
57
|
+
|
58
|
+
location = Google::Maps.geocode('Science Park 400, Amsterdam').first
|
59
|
+
components = location.components
|
60
|
+
expect(components['administrative_area_level_1']).to eq(['Noord-Holland'])
|
61
|
+
expect(components['administrative_area_level_2']).to eq(['Government of Amsterdam'])
|
62
|
+
expect(components['country']).to eq(['The Netherlands'])
|
63
|
+
expect(components['establishment']).to eq(['University of Amsterdam'])
|
64
|
+
expect(components['locality']).to eq(['Amsterdam'])
|
65
|
+
expect(components['political']).to eq(
|
66
|
+
['Middenmeer', 'Watergraafsmeer', 'Amsterdam', 'Government of Amsterdam', 'Noord-Holland', 'The Netherlands']
|
67
|
+
)
|
68
|
+
expect(components['postal_code']).to eq(['1098 XH'])
|
69
|
+
expect(components['route']).to eq(['Science Park Amsterdam'])
|
70
|
+
expect(components['street_number']).to eq(['400'])
|
71
|
+
expect(components['sublocality']).to eq(%w[Middenmeer Watergraafsmeer])
|
72
|
+
end
|
73
|
+
|
55
74
|
it 'should handle multiple location for an address' do
|
56
75
|
stub_response('geocoder/amsterdam-en.json')
|
57
76
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel van Hoesel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
285
285
|
- !ruby/object:Gem::Version
|
286
286
|
version: '0'
|
287
287
|
requirements: []
|
288
|
-
rubygems_version: 3.0.
|
288
|
+
rubygems_version: 3.0.3
|
289
289
|
signing_key:
|
290
290
|
specification_version: 4
|
291
291
|
summary: Ruby wrapper for the Google Maps API
|