Use administrative_area 'name' when 'code' is empty

Created on 3 March 2025, 9 days ago

Problem/Motivation

Since the fix of the parent bug report, Geocoder uses the 'code' field for administrative_area. This field can be empty, as seen in the screenshot (coordinates in Europe, Nominatim provider), even though the 'name' field might contain data.

Steps to reproduce

Use Nominatim provider. Set a breakpoint at line 79 of DumperPluginManager.php, and see that the 'code' field is empty.

Proposed resolution

Change the code: use the 'code' field if it's not empty, otherwise use the 'name' field if it's not empty.

    if (!empty($geojson_array['properties']['adminLevels'])) {
      $administrative_area_array = array_shift($geojson_array['properties']['adminLevels']);
      if(!empty($administrative_area_array['code'])) {
        $administrative_area = $administrative_area_array['code'];
      } elseif(!empty($administrative_area_array['name'])) {
        $administrative_area = $administrative_area_array['name'];
      }
🐛 Bug report
Status

Active

Version

4.26

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024