google-geocoder 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/VERSION +1 -1
- data/bin/geo +5 -2
- data/google-geocoder.gemspec +1 -1
- data/lib/google_geocoder.rb +28 -24
- metadata +3 -3
data/CHANGES
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/bin/geo
CHANGED
@@ -31,9 +31,12 @@ class Geo
|
|
31
31
|
puts "Version: #{File.open(File::dirname(__FILE__) + "/../VERSION").readlines().first}"
|
32
32
|
when /(.*)/ then
|
33
33
|
begin
|
34
|
-
@geocoder.query(query)
|
34
|
+
result = @geocoder.query(query)
|
35
|
+
|
36
|
+
puts "No results." if result.size == 0
|
35
37
|
rescue Exception => e
|
36
|
-
|
38
|
+
p e.class.name
|
39
|
+
puts "Error: " + e.message unless e.message.empty?
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
data/google-geocoder.gemspec
CHANGED
data/lib/google_geocoder.rb
CHANGED
@@ -45,33 +45,37 @@ module Google
|
|
45
45
|
response = call_service(request)
|
46
46
|
|
47
47
|
raise(GeocoderServerIsDown) if response.empty?
|
48
|
-
|
49
|
-
raise(InvalidResponse, response['results']) if response['status'] != "OK" # success
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
49
|
+
if response['status'] == "ZERO_RESULTS"
|
50
|
+
[]
|
51
|
+
else
|
52
|
+
raise(InvalidResponse, response['results']) if response['status'] != "OK" # success
|
53
|
+
|
54
|
+
root = response["results"][0]
|
55
|
+
address_components = root["address_components"]
|
56
|
+
geometry = root["geometry"]
|
57
|
+
|
58
|
+
country = address_component(address_components, "country")
|
59
|
+
locality = address_component(address_components, "locality")
|
60
|
+
administrative_area_l1 = address_component(address_components, "administrative_area_level_1")
|
61
|
+
administrative_area_l2 = address_component(address_components, "administrative_area_level_2")
|
62
|
+
|
63
|
+
latitude = geometry["location"]["lat"]
|
64
|
+
longitude = geometry["location"]["lng"]
|
65
|
+
|
66
|
+
puts "Country: #{country['long_name']} (#{country['short_name']})"
|
67
|
+
puts "Locality: #{locality['long_name']} (#{locality['short_name']})"
|
68
|
+
puts "Administrative Area (level 1): #{administrative_area_l1['long_name']} (#{administrative_area_l1['short_name']})"
|
69
|
+
puts "Administrative Area (level 2): #{administrative_area_l2['long_name']} (#{administrative_area_l2['short_name']})" unless administrative_area_l2.nil?
|
70
|
+
|
71
|
+
puts "Latitude: #{latitude}"
|
72
|
+
puts "Longitude: #{longitude}"
|
73
|
+
|
74
|
+
[latitude, longitude]
|
75
|
+
end
|
72
76
|
rescue OpenURI::HTTPError
|
73
77
|
raise(GeocoderServerIsDown)
|
74
|
-
end
|
78
|
+
end
|
75
79
|
end
|
76
80
|
|
77
81
|
private
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexander Shvets
|