File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
tests/Geocoder/Tests/Provider Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,16 @@ public function getGeocodedData($address)
52
52
53
53
$ result = json_decode ($ this ->executeQuery ($ address ));
54
54
55
+ //Try to extract the region name and code
56
+ $ region = null ;
57
+ $ regionCode = null ;
58
+ if (isset ($ result ->subdivisions ) && is_array ($ result ->subdivisions ) && !empty ($ result ->subdivisions )) {
59
+ $ lastSubdivision = array_pop ($ result ->subdivisions );
60
+
61
+ $ region = (isset ($ lastSubdivision ->names ->{$ this ->locale }) ? $ lastSubdivision ->names ->{$ this ->locale } : null );
62
+ $ regionCode = (isset ($ lastSubdivision ->iso_code ) ? $ lastSubdivision ->iso_code : null );
63
+ }
64
+
55
65
return array ($ this ->fixEncoding (array_merge ($ this ->getDefaults (), array (
56
66
'countryCode ' => (isset ($ result ->country ->iso_code ) ? $ result ->country ->iso_code : null ),
57
67
'country ' => (isset ($ result ->country ->names ->{$ this ->locale }) ? $ result ->country ->names ->{$ this ->locale } : null ),
@@ -60,6 +70,8 @@ public function getGeocodedData($address)
60
70
'longitude ' => (isset ($ result ->location ->longitude ) ? $ result ->location ->longitude : null ),
61
71
'timezone ' => (isset ($ result ->location ->timezone ) ? $ result ->location ->timezone : null ),
62
72
'zipcode ' => (isset ($ result ->location ->postalcode ) ? $ result ->location ->postalcode : null ),
73
+ 'region ' => $ region ,
74
+ 'regionCode ' => $ regionCode
63
75
))));
64
76
}
65
77
Original file line number Diff line number Diff line change @@ -99,8 +99,8 @@ public static function provideDataForRetrievingGeodata()
99
99
'cityDistrict ' => null ,
100
100
'county ' => null ,
101
101
'countyCode ' => null ,
102
- 'region ' => null ,
103
- 'regionCode ' => null ,
102
+ 'region ' => ' Hamburg ' ,
103
+ 'regionCode ' => ' HH ' ,
104
104
'country ' => 'Germany ' ,
105
105
'countryCode ' => 'DE ' ,
106
106
'timezone ' => null ,
You can’t perform that action at this time.
0 commit comments