Skip to content

Commit 79fa896

Browse files
committed
Add osm tag filter feature & limit filter
1 parent 742a10d commit 79fa896

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/Provider/Photon/Photon.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public function reverseQuery(ReverseQuery $query): Collection
106106
.http_build_query([
107107
'lat' => $latitude,
108108
'lon' => $longitude,
109-
'query_string_filter' => $query->getData('query_string_filter'),
109+
'osm_tag' => $query->getData('osm_tag'),
110+
'limit' => $query->getLimit(),
110111
'lang' => $query->getLocale(),
111112
]);
112113

src/Provider/Photon/Tests/PhotonTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Geocoder\Provider\Photon\Tests;
1414

1515
use Geocoder\IntegrationTest\BaseTestCase;
16+
use Geocoder\Provider\Photon\Model\PhotonAddress;
1617
use Geocoder\Query\GeocodeQuery;
1718
use Geocoder\Query\ReverseQuery;
1819
use Geocoder\Provider\Photon\Photon;
@@ -97,7 +98,8 @@ public function testGeocodeQueryWithNamedResult()
9798
public function testReverseQuery()
9899
{
99100
$provider = Photon::withKomootServer($this->getHttpClient());
100-
$results = $provider->reverseQuery(ReverseQuery::fromCoordinates(52, 10));
101+
$reverseQuery = ReverseQuery::fromCoordinates(52, 10)->withLimit(1);
102+
$results = $provider->reverseQuery($reverseQuery);
101103

102104
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results);
103105
$this->assertCount(1, $results);
@@ -121,16 +123,19 @@ public function testReverseQuery()
121123
$this->assertEquals('Sehlem', $result->getDistrict());
122124
}
123125

124-
public function testReverseQueryWithOsmDataFilter()
126+
public function testReverseQueryWithOsmTagFilter()
125127
{
126128
$provider = Photon::withKomootServer($this->getHttpClient());
127-
$reverseQuery = ReverseQuery::fromCoordinates(45.73179, 6.03248)
128-
->withData('query_string_filter', 'osm_key:place')
129-
->withLimit(1);
130-
/** @var \Geocoder\Provider\Photon\Model\PhotonAddress $result */
131-
$result = $provider->reverseQuery($reverseQuery)->first();
132-
133-
$this->assertEquals('place', $result->getOSMTag()->key);
134-
$this->assertEquals('locality', $result->getOSMTag()->value);
129+
$reverseQuery = ReverseQuery::fromCoordinates(52.51644, 13.38890)
130+
->withData('osm_tag', 'amenity:pharmacy')
131+
->withLimit(3);
132+
$results = $provider->reverseQuery($reverseQuery);
133+
134+
$this->assertCount(3, $results);
135+
foreach ($results as $result) {
136+
$this->assertInstanceOf(PhotonAddress::class, $result);
137+
$this->assertEquals('amenity', $result->getOSMTag()->key);
138+
$this->assertEquals('pharmacy', $result->getOSMTag()->value);
139+
}
135140
}
136141
}

0 commit comments

Comments
 (0)