Skip to content

Commit db4ab1b

Browse files
authored
[Nominatim] Add support for "quarter" (OpenStreetMap) (#1099)
1 parent 46863bb commit db4ab1b

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

src/Provider/Nominatim/Model/NominatimAddress.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ final class NominatimAddress extends Address
3434
*/
3535
private $displayName;
3636

37+
/**
38+
* @var string|null
39+
*/
40+
private $quarter;
41+
3742
/**
3843
* @var string|null
3944
*/
@@ -196,4 +201,25 @@ public function withType(string $type = null): self
196201

197202
return $new;
198203
}
204+
205+
/**
206+
* @return string|null
207+
*/
208+
public function getQuarter(): ?string
209+
{
210+
return $this->quarter;
211+
}
212+
213+
/**
214+
* @param string|null $quarter
215+
*
216+
* @return NominatimAddress
217+
*/
218+
public function withQuarter(string $quarter = null): self
219+
{
220+
$new = clone $this;
221+
$new->quarter = $quarter;
222+
223+
return $new;
224+
}
199225
}

src/Provider/Nominatim/Nominatim.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,15 @@ private function jsonResultToLocation(\stdClass $place, bool $reverse): Location
228228

229229
$builder->setBounds($place->boundingbox[0], $place->boundingbox[2], $place->boundingbox[1], $place->boundingbox[3]);
230230

231+
/** @var NominatimAddress $location */
231232
$location = $builder->build(NominatimAddress::class);
232233
$location = $location->withAttribution($place->licence);
233234
$location = $location->withDisplayName($place->display_name);
234235

236+
if (isset($place->address->quarter)) {
237+
$location = $location->withQuarter($place->address->quarter);
238+
}
239+
235240
if (isset($place->osm_id)) {
236241
$location = $location->withOSMId(intval($place->osm_id));
237242
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s:625:"[{"place_id":219601027,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"way","osm_id":625792441,"boundingbox":["52.1875624","52.1884584","20.9880299","20.9890588"],"lat":"52.18810065","lon":"20.98854576935957","display_name":"Woronicza, Służewiec, Mokotów, Warszawa, województwo mazowieckie, Polska","place_rank":22,"category":"landuse","type":"construction","importance":0.5,"address":{"landuse":"Woronicza","quarter":"Służewiec","suburb":"Mokotów","city_district":"Warszawa","city":"Warszawa","state":"województwo mazowieckie","country":"Polska","country_code":"pl"}}]";

src/Provider/Nominatim/Tests/NominatimTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ public function testGeocodeWithRealAddress()
109109
$this->assertEquals('yes', $result->getType());
110110
}
111111

112+
public function testGeocodeWithRealAddressThatReturnsOptionalQuarter()
113+
{
114+
$provider = Nominatim::withOpenStreetMapServer($this->getHttpClient(), 'Geocoder PHP/Nominatim Provider/Nominatim Test');
115+
$results = $provider->geocodeQuery(GeocodeQuery::create('woronicza 17, warszawa, polska'));
116+
117+
$this->assertCount(1, $results);
118+
119+
/* @var \Geocoder\Provider\Nominatim\Model\NominatimAddress $result */
120+
$this->assertEquals('Służewiec', $results->first()->getQuarter());
121+
}
122+
112123
public function testGeocodeWithCountrycodes()
113124
{
114125
$provider = Nominatim::withOpenStreetMapServer($this->getHttpClient(), 'Geocoder PHP/Nominatim Provider/Nominatim Test');

0 commit comments

Comments
 (0)