From 7cb656cadf98fcf370c50473c1a21a1fa3325032 Mon Sep 17 00:00:00 2001 From: fbuchlak <30214087+fbuchlak@users.noreply.github.com> Date: Sat, 15 Mar 2025 18:44:39 +0100 Subject: [PATCH 1/2] feat: [Photon] support lat/lon in geocode query --- src/Provider/Photon/Photon.php | 2 ++ ...o_83d30d7d0b77d2526ba7d750ad29a2daae002647 | 1 + ...o_e564cba10f78e298ecde7f804fbfb15d7d430ebc | 1 + src/Provider/Photon/Tests/PhotonTest.php | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_83d30d7d0b77d2526ba7d750ad29a2daae002647 create mode 100644 src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e564cba10f78e298ecde7f804fbfb15d7d430ebc diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index caed4ecab..1da16efb6 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -71,6 +71,8 @@ public function geocodeQuery(GeocodeQuery $query): Collection 'layer' => $query->getData('layer'), 'limit' => $query->getLimit(), 'lang' => $query->getLocale(), + 'lat' => $query->getData('lat'), + 'lon' => $query->getData('lon'), ]); $osmTagFilters = $this->buildOsmTagFilterQuery($query->getData('osm_tag')); if (!empty($osmTagFilters)) { diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_83d30d7d0b77d2526ba7d750ad29a2daae002647 b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_83d30d7d0b77d2526ba7d750ad29a2daae002647 new file mode 100644 index 000000000..7296f064e --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_83d30d7d0b77d2526ba7d750ad29a2daae002647 @@ -0,0 +1 @@ +s:535:"{"features":[{"geometry":{"coordinates":[2.3200410217200766,48.8588897],"type":"Point"},"type":"Feature","properties":{"osm_type":"R","osm_id":7444,"extent":[2.224122,48.902156,2.4697602,48.8155755],"country":"France","osm_key":"boundary","city":"Paris","countrycode":"FR","osm_value":"administrative","postcode":"75000;75001;75002;75003;75004;75005;75006;75007;75008;75009;75010;75011;75012;75013;75014;75015;75016;75017;75018;75019;75020;75116","name":"Paris","state":"Île-de-France","type":"district"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e564cba10f78e298ecde7f804fbfb15d7d430ebc b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e564cba10f78e298ecde7f804fbfb15d7d430ebc new file mode 100644 index 000000000..80cb7b8b9 --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_e564cba10f78e298ecde7f804fbfb15d7d430ebc @@ -0,0 +1 @@ +s:373:"{"features":[{"geometry":{"coordinates":[-95.555513,33.6617962],"type":"Point"},"type":"Feature","properties":{"osm_type":"R","osm_id":115357,"extent":[-95.6279396,33.7383866,-95.4354115,33.6206345],"country":"United States","osm_key":"place","countrycode":"US","osm_value":"town","name":"Paris","county":"Lamar","state":"Texas","type":"city"}}],"type":"FeatureCollection"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index 2ae88c655..1cacdf8b3 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -135,6 +135,25 @@ public function testGeocodeQueryWithMultipleOsmTagFilter(): void $this->assertGreaterThan(0, $countGalleries); } + public function testGeocodeQueryWithLatLon(): void + { + $provider = Photon::withKomootServer($this->getHttpClient()); + + $query = GeocodeQuery::create('Paris')->withLimit(1); + $results = $provider->geocodeQuery($query); + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertCount(1, $results); + $this->assertEquals('France', $results->first()->getCountry()); + + $query = $query + ->withData('lat', 33.661426) + ->withData('lon', -95.556321); + $results = $provider->geocodeQuery($query); + $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertCount(1, $results); + $this->assertEquals('United States', $results->first()->getCountry()); + } + public function testReverseQuery(): void { $provider = Photon::withKomootServer($this->getHttpClient()); From b142c1d8a458e8998c729c5e80083b0c7f4592c2 Mon Sep 17 00:00:00 2001 From: fbuchlak <30214087+fbuchlak@users.noreply.github.com> Date: Thu, 20 Mar 2025 11:14:56 +0100 Subject: [PATCH 2/2] style: [photon] use class name resolution in test --- src/Provider/Photon/Tests/PhotonTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index 1cacdf8b3..721df89da 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -13,6 +13,7 @@ namespace Geocoder\Provider\Photon\Tests; use Geocoder\IntegrationTest\BaseTestCase; +use Geocoder\Model\AddressCollection; use Geocoder\Provider\Photon\Model\PhotonAddress; use Geocoder\Provider\Photon\Photon; use Geocoder\Query\GeocodeQuery; @@ -141,7 +142,7 @@ public function testGeocodeQueryWithLatLon(): void $query = GeocodeQuery::create('Paris')->withLimit(1); $results = $provider->geocodeQuery($query); - $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertInstanceOf(AddressCollection::class, $results); $this->assertCount(1, $results); $this->assertEquals('France', $results->first()->getCountry()); @@ -149,7 +150,7 @@ public function testGeocodeQueryWithLatLon(): void ->withData('lat', 33.661426) ->withData('lon', -95.556321); $results = $provider->geocodeQuery($query); - $this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); + $this->assertInstanceOf(AddressCollection::class, $results); $this->assertCount(1, $results); $this->assertEquals('United States', $results->first()->getCountry()); }