Repository: geocoder-php/Geocoder (language: php)

Issue:
[Nominatim] Neighbourhood field
Some addresses have a "neighbourhood" field, for example : 

https://nominatim.openstreetmap.org/reverse?format=xml&lat=35.685939&lon=139.811695&zoom=18&addressdetails=1

In jsonResultToLocation(), this field is not processed, so we can't get that value through the reverseQuery() method.



Discussion / hints:
Hello @Jeremylepr,

Thanks for the idea.
It should be relatively easy to implement, could you create a PR ?

Fix patch:
diff --git a/src/Provider/Nominatim/Model/NominatimAddress.php b/src/Provider/Nominatim/Model/NominatimAddress.php
index 50ddbfc0f..fa07e36a8 100644
--- a/src/Provider/Nominatim/Model/NominatimAddress.php
+++ b/src/Provider/Nominatim/Model/NominatimAddress.php
@@ -64,6 +64,11 @@ final class NominatimAddress extends Address
      */
     private $tags;
 
+    /**
+     * @var string|null
+     */
+    private $neighbourhood;
+
     /**
      * @return string|null
      */
@@ -270,4 +275,25 @@ public function withTags(array $tags = null): self
 
         return $new;
     }
+
+    /**
+     * @return string|null
+     */
+    public function getNeighbourhood()
+    {
+        return $this->neighbourhood;
+    }
+
+    /**
+     * @param string|null $neighbourhood
+     *
+     * @return NominatimAddress
+     */
+    public function withNeighbourhood(string $neighbourhood = null): self
+    {
+        $new = clone $this;
+        $new->neighbourhood = $neighbourhood;
+
+        return $new;
+    }
 }
diff --git a/src/Provider/Nominatim/Nominatim.php b/src/Provider/Nominatim/Nominatim.php
index 00df9b40c..f0c09ce70 100644
--- a/src/Provider/Nominatim/Nominatim.php
+++ b/src/Provider/Nominatim/Nominatim.php
@@ -244,6 +244,9 @@ private function jsonResultToLocation(\stdClass $place, bool $reverse): Location
         if (isset($place->address->quarter)) {
             $location = $location->withQuarter($place->address->quarter);
         }
+        if (isset($place->address->neighbourhood)) {
+            $location = $location->withNeighbourhood($place->address->neighbourhood);
+        }
         if (isset($place->osm_id)) {
             $location = $location->withOSMId(intval($place->osm_id));
         }
diff --git a/src/Provider/Nominatim/Tests/.cached_responses/nominatim.openstreetmap.org_237e0bcaa26f36e484a002f8238e2645591e3622 b/src/Provider/Nominatim/Tests/.cached_responses/nominatim.openstreetmap.org_237e0bcaa26f36e484a002f8238e2645591e3622
new file mode 100644
index 000000000..619c2d71a
--- /dev/null
+++ b/src/Provider/Nominatim/Tests/.cached_responses/nominatim.openstreetmap.org_237e0bcaa26f36e484a002f8238e2645591e3622
@@ -0,0 +1,1 @@
+s:562:"{"place_id":112067733,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"way","osm_id":28063955,"lat":"35.686010380404326","lon":"139.8116922926535","place_rank":26,"category":"highway","type":"tertiary","importance":0.09999999999999998,"addresstype":"road","name":null,"display_name":"Sarue 1-chome, Koto, Tokyo, 135-0002, Japan","address":{"neighbourhood":"Sarue 1-chome","city":"Koto","postcode":"135-0002","country":"Japan","country_code":"jp"},"boundingbox":["35.6859434","35.68617","139.8098558","139.8160149"]}";
\ No newline at end of file
diff --git a/src/Provider/Nominatim/Tests/NominatimTest.php b/src/Provider/Nominatim/Tests/NominatimTest.php
index 6e0f759b2..c318ca552 100644
--- a/src/Provider/Nominatim/Tests/NominatimTest.php
+++ b/src/Provider/Nominatim/Tests/NominatimTest.php
@@ -236,4 +236,21 @@ public function testGeocodeNoCountry()
         $this->assertEquals('way', $result->getOSMType());
         $this->assertEquals(null, $result->getCountry());
     }
+
+    public function testGeocodeNeighbourhood()
+    {
+        $provider = Nominatim::withOpenStreetMapServer($this->getHttpClient(), 'Geocoder PHP/Nominatim Provider/Nominatim Test');
+        $results = $provider->reverseQuery(ReverseQuery::fromCoordinates(35.685939, 139.811695)->withLocale('en'));
+
+        $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
+        $this->assertCount(1, $results);
+
+        /** @var \Geocoder\Provider\Nominatim\Model\NominatimAddress $result */
+        $result = $results->first();
+        $this->assertInstanceOf('\Geocoder\Model\Address', $result);
+        $this->assertEquals('Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', $result->getAttribution());
+
+        $this->assertEquals('Sarue 1-chome', $result->getNeighbourhood());
+        $this->assertEquals('Japan', $result->getCountry());
+    }
 }


Test patch: