Skip to content

Commit

Permalink
Add support of osm tag filter for geocode query
Browse files Browse the repository at this point in the history
  • Loading branch information
ybert committed Jul 31, 2023
1 parent 0598c64 commit 97511a5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Provider/Photon/Photon.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection
.'/api?'
.http_build_query([
'q' => $address,
'osm_tag' => $query->getData('osm_tag'),
'limit' => $query->getLimit(),
'lang' => $query->getLocale(),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/Photon/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You can use your own photon instance :
// New instance of the provider :
$provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url');
// Run geocode or reverse query
$query = $provider->geocodeQuery(new \Geocoder\Query\GeocodeQuery('Paris'));
$query = $provider->geocodeQuery(\Geocoder\Query\GeocodeQuery::create('Paris'));
$reverseQuery = $provider->reverseQuery(\Geocoder\Query\ReverseQuery::fromCoordinates(48.86036 ,2.33852));
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s:2187:"{"features":[{"geometry":{"coordinates":[2.2978602225671843,48.8643133],"type":"Point"},"type":"Feature","properties":{"osm_id":79219308,"extent":[2.2971088,48.8647083,2.2984772,48.8639024],"country":"France","city":"Paris","countrycode":"FR","postcode":"75116","locality":"Quartier de Chaillot","type":"house","osm_type":"W","osm_key":"tourism","street":"Rue Gaston de Saint-Paul","district":"Paris","osm_value":"museum","name":"Musée d'Art Moderne de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3518758,48.850724],"type":"Point"},"type":"Feature","properties":{"osm_id":237003117,"country":"France","city":"Paris","countrycode":"FR","postcode":"75005","locality":"Quartier Saint-Victor","type":"house","osm_type":"N","osm_key":"tourism","street":"Quai de la Tournelle","district":"Paris","osm_value":"museum","name":"Musée de l'Assistance Publique Hôpitaux de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3450724,48.8640506],"type":"Point"},"type":"Feature","properties":{"osm_id":3087374948,"country":"France","city":"Paris","countrycode":"FR","postcode":"75001","locality":"Les Halles","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue du Jour","district":"Paris","osm_value":"museum","name":"Musée du Barreau de Paris","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3153496472839956,48.866042],"type":"Point"},"type":"Feature","properties":{"osm_id":2778854,"extent":[2.3143339,48.866628,2.3156049,48.8654594],"country":"France","city":"Paris","countrycode":"FR","postcode":"75008","locality":"Quartier des Champs-Élysées","type":"house","osm_type":"R","osm_key":"tourism","street":"Avenue Winston Churchill","district":"Paris","osm_value":"museum","name":"Petit Palais","state":"Île-de-France"}},{"geometry":{"coordinates":[2.3453019,48.8625016],"type":"Point"},"type":"Feature","properties":{"osm_id":1028569468,"country":"France","city":"Paris","countrycode":"FR","postcode":"75001","locality":"Les Halles","type":"house","osm_type":"N","osm_key":"tourism","street":"Rue du Cinéma","district":"Paris","osm_value":"museum","name":"Salle des collections","state":"Île-de-France"}}],"type":"FeatureCollection"}";
16 changes: 16 additions & 0 deletions src/Provider/Photon/Tests/PhotonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ public function testGeocodeQueryWithNamedResult()
$this->assertEquals('The Sherlock Holmes Museum and shop', $result->getName());
}

public function testGeocodeQueryWithOsmTagFilter()
{
$provider = Photon::withKomootServer($this->getHttpClient());
$query = GeocodeQuery::create('Paris')
->withData('osm_tag', 'tourism:museum')
->withLimit(5);
$results = $provider->geocodeQuery($query);

$this->assertCount(5, $results);
foreach ($results as $result) {
$this->assertInstanceOf(PhotonAddress::class, $result);
$this->assertEquals('tourism', $result->getOSMTag()->key);
$this->assertEquals('museum', $result->getOSMTag()->value);
}
}

public function testReverseQuery()
{
$provider = Photon::withKomootServer($this->getHttpClient());
Expand Down

0 comments on commit 97511a5

Please sign in to comment.