google_geocoding 0.1.3 → 0.1.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.
- data/VERSION +1 -1
- data/google_geocoding.gemspec +1 -1
- data/lib/google_geocoding/response.rb +21 -28
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/google_geocoding.gemspec
CHANGED
@@ -6,7 +6,7 @@ module GoogleGeocoding
|
|
6
6
|
def initialize(resp_body)
|
7
7
|
@data = JSON.parse(resp_body)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
# Return the status code included in the server response.
|
11
11
|
#
|
12
12
|
# @return [Integer]
|
@@ -14,17 +14,17 @@ module GoogleGeocoding
|
|
14
14
|
def status_code
|
15
15
|
Integer(@data["Status"]["code"])
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Return whether response successfully resolved the geolocation
|
19
19
|
def success?
|
20
20
|
status_code == 200
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
# Return whether response failed to resolved the geolocation
|
24
24
|
def failure?
|
25
25
|
!success?
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# Return the placemarks included in the response.
|
29
29
|
#
|
30
30
|
# @return [Array<Placemark>]
|
@@ -33,7 +33,7 @@ module GoogleGeocoding
|
|
33
33
|
raise Errors::ServiceError.build(status_code)
|
34
34
|
else
|
35
35
|
placemarks = []
|
36
|
-
|
36
|
+
|
37
37
|
@data["Placemark"].each do |placemark_data|
|
38
38
|
details = placemark_data["AddressDetails"]
|
39
39
|
coordinates = placemark_data["Point"]["coordinates"][2..1]
|
@@ -41,37 +41,30 @@ module GoogleGeocoding
|
|
41
41
|
placemark = Placemark.new
|
42
42
|
placemark.accurracy = accurracy
|
43
43
|
placemark.coordinates = coordinates
|
44
|
-
|
45
|
-
next if accurracy >= 9
|
46
44
|
|
47
|
-
if
|
48
|
-
country = details["Country"]
|
45
|
+
if country = details["Country"]
|
49
46
|
placemark.country_name = country["CountryName"],
|
50
47
|
placemark.country_code = country["CountryNameCode"]
|
51
|
-
|
52
|
-
if
|
53
|
-
admarea = country["AdministrativeArea"]
|
48
|
+
|
49
|
+
if admarea = country["AdministrativeArea"]
|
54
50
|
placemark.region = admarea["AdministrativeAreaName"]
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
if accurracy >= 6
|
68
|
-
placemark.street = locality["Thoroughfare"]["ThoroughfareName"]
|
69
|
-
end
|
51
|
+
subadmarea = admarea["SubAdministrativeArea"]
|
52
|
+
locality = subadmarea ? subadmarea["Locality"] : admarea["Locality"]
|
53
|
+
|
54
|
+
if locality
|
55
|
+
placemark.city = locality["LocalityName"]
|
56
|
+
|
57
|
+
if postal_code = locality["PostalCode"]
|
58
|
+
placemark.postal_code = postal_code["PostalCodeNumber"]
|
59
|
+
end
|
60
|
+
|
61
|
+
if thoroughfare = locality["Thoroughfare"]
|
62
|
+
placemark.street = thoroughfare["ThoroughfareName"]
|
70
63
|
end
|
71
64
|
end
|
72
65
|
end
|
73
66
|
end
|
74
|
-
|
67
|
+
|
75
68
|
placemarks << placemark
|
76
69
|
end
|
77
70
|
placemarks
|