Skip to content

Commit 0f47405

Browse files
authored
feat: [Photon] support lat/lon in geocode query (#1248)
* feat: [Photon] support lat/lon in geocode query * style: [photon] use class name resolution in test
1 parent af1105b commit 0f47405

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/Provider/Photon/Photon.php

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function geocodeQuery(GeocodeQuery $query): Collection
7171
'layer' => $query->getData('layer'),
7272
'limit' => $query->getLimit(),
7373
'lang' => $query->getLocale(),
74+
'lat' => $query->getData('lat'),
75+
'lon' => $query->getData('lon'),
7476
]);
7577
$osmTagFilters = $this->buildOsmTagFilterQuery($query->getData('osm_tag'));
7678
if (!empty($osmTagFilters)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}";

src/Provider/Photon/Tests/PhotonTest.php

+20
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\Model\AddressCollection;
1617
use Geocoder\Provider\Photon\Model\PhotonAddress;
1718
use Geocoder\Provider\Photon\Photon;
1819
use Geocoder\Query\GeocodeQuery;
@@ -135,6 +136,25 @@ public function testGeocodeQueryWithMultipleOsmTagFilter(): void
135136
$this->assertGreaterThan(0, $countGalleries);
136137
}
137138

139+
public function testGeocodeQueryWithLatLon(): void
140+
{
141+
$provider = Photon::withKomootServer($this->getHttpClient());
142+
143+
$query = GeocodeQuery::create('Paris')->withLimit(1);
144+
$results = $provider->geocodeQuery($query);
145+
$this->assertInstanceOf(AddressCollection::class, $results);
146+
$this->assertCount(1, $results);
147+
$this->assertEquals('France', $results->first()->getCountry());
148+
149+
$query = $query
150+
->withData('lat', 33.661426)
151+
->withData('lon', -95.556321);
152+
$results = $provider->geocodeQuery($query);
153+
$this->assertInstanceOf(AddressCollection::class, $results);
154+
$this->assertCount(1, $results);
155+
$this->assertEquals('United States', $results->first()->getCountry());
156+
}
157+
138158
public function testReverseQuery(): void
139159
{
140160
$provider = Photon::withKomootServer($this->getHttpClient());

0 commit comments

Comments
 (0)