Skip to content

Commit e62a4b5

Browse files
committed
Fix OpenCage provider with apikey
1 parent 083922e commit e62a4b5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Geocoder/Provider/OpenCage.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,15 @@ private function executeQuery($query)
128128
];
129129
}
130130

131-
$comp = $location['components'];
131+
$comp = $location['components'];
132+
133+
$adminLevels = [];
134+
foreach (['state', 'county'] as $i => $component) {
135+
if (isset($comp[$component])) {
136+
$adminLevels[] = ['name' => $comp[$component], 'level' => $i + 1];
137+
}
138+
}
139+
132140
$results[] = array_merge($this->getDefaults(), array(
133141
'latitude' => $location['geometry']['lat'],
134142
'longitude' => $location['geometry']['lng'],
@@ -138,8 +146,7 @@ private function executeQuery($query)
138146
'subLocality' => isset($comp['suburb'] ) ? $comp['suburb'] : null,
139147
'locality' => isset($comp['city'] ) ? $comp['city'] : null,
140148
'postalCode' => isset($comp['postcode'] ) ? $comp['postcode'] : null,
141-
'county' => isset($comp['county'] ) ? $comp['county'] : null,
142-
'region' => isset($comp['state'] ) ? $comp['state'] : null,
149+
'adminLevels' => $adminLevels,
143150
'country' => isset($comp['country'] ) ? $comp['country'] : null,
144151
'countryCode' => isset($comp['country_code']) ? strtoupper($comp['country_code']) : null,
145152
'timezone' => isset($location['annotations']['timezone']['name']) ? $location['annotations']['timezone']['name'] : null,

0 commit comments

Comments
 (0)