Skip to content

Commit 0811256

Browse files
authored
Merge branch 'master' into feature/provider-geocode-5
2 parents a567dfd + 7c080fa commit 0811256

13 files changed

+153
-12
lines changed

src/Common/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"nyholm/nsa": "^1.1",
2424
"phpunit/phpunit": "^9.5",
25-
"symfony/stopwatch": "~2.5 || ~5.0"
25+
"symfony/stopwatch": "~2.5 || ~5.0 || ~7.0"
2626
},
2727
"suggest": {
2828
"symfony/stopwatch": "If you want to use the TimedGeocoder"

src/Provider/Photon/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
## 0.7.0
6+
7+
### Added
8+
9+
- Add support for PHP 8.3 and 8.4
10+
- Add support for OpenStreetMap filters
11+
12+
### Removed
13+
14+
- Drop support for PHP 7.3
15+
516
## 0.6.0
617

718
### Added

src/Provider/Photon/Photon.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public function geocodeQuery(GeocodeQuery $query): Collection
7171
'limit' => $query->getLimit(),
7272
'lang' => $query->getLocale(),
7373
]);
74+
$osmTagFilters = $this->buildOsmTagFilterQuery($query->getData('osm_tag'));
75+
if (!empty($osmTagFilters)) {
76+
$url .= $osmTagFilters;
77+
}
7478

7579
$json = $this->executeQuery($url);
7680

@@ -98,8 +102,13 @@ public function reverseQuery(ReverseQuery $query): Collection
98102
.http_build_query([
99103
'lat' => $latitude,
100104
'lon' => $longitude,
105+
'limit' => $query->getLimit(),
101106
'lang' => $query->getLocale(),
102107
]);
108+
$osmTagFilters = $this->buildOsmTagFilterQuery($query->getData('osm_tag'));
109+
if (!empty($osmTagFilters)) {
110+
$url .= $osmTagFilters;
111+
}
103112

104113
$json = $this->executeQuery($url);
105114

@@ -158,6 +167,25 @@ public function getName(): string
158167
return 'photon';
159168
}
160169

170+
/**
171+
* @param string|array<int, string>|null $filters
172+
*/
173+
private function buildOsmTagFilterQuery($filters): string
174+
{
175+
$query = '';
176+
if (null === $filters) {
177+
return $query;
178+
}
179+
if (is_string($filters)) {
180+
return '&osm_tag='.urlencode($filters);
181+
}
182+
foreach ($filters as $filter) {
183+
$query .= '&osm_tag='.urlencode($filter);
184+
}
185+
186+
return $query;
187+
}
188+
161189
private function executeQuery(string $url): \stdClass
162190
{
163191
$content = $this->getUrlContents($url);

src/Provider/Photon/Readme.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,56 @@
1010
This is the photon provider from the PHP Geocoder. This is a **READ ONLY** repository. See the
1111
[main repo](https://github.com/geocoder-php/Geocoder) for information and documentation.
1212

13-
### Install
14-
13+
## Install
1514
```bash
1615
composer require geocoder-php/photon-provider
1716
```
1817

19-
### Contribute
18+
## API Documentation
19+
https://photon.komoot.io
20+
https://github.com/komoot/photon
21+
22+
## Usage
23+
24+
### Basic usage
25+
You can use your own photon instance :
26+
```php
27+
// New instance of the provider :
28+
$provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url');
29+
// Run geocode or reverse query
30+
$query = $provider->geocodeQuery(\Geocoder\Query\GeocodeQuery::create('Paris'));
31+
$reverseQuery = $provider->reverseQuery(\Geocoder\Query\ReverseQuery::fromCoordinates(48.86036 ,2.33852));
32+
```
33+
34+
### OSM Tag Feature
35+
You can search for location data based on osm tag filters.
36+
37+
For example, you can filter a geocode query to only include results of type 'place'. You can even restrict it to only have places of type 'city'.
38+
In the reverse geocoding context you can search for the 3 pharmacies closest to a location.
39+
40+
To see what you can do with this feature, check [the official photon documentation](https://github.com/komoot/photon#filter-results-by-tags-and-values)
41+
42+
Below is an example to query the 3 pharmacies closest to a location :
43+
```php
44+
$provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url');
45+
$reverseQuery = \Geocoder\Query\ReverseQuery::fromCoordinates(52.51644, 13.38890)
46+
->withData('osm_tag', 'amenity:pharmacy')
47+
->withLimit(3);
48+
49+
$results = $provider->reverseQuery($reverseQuery);
50+
```
51+
52+
You can combine multiple osm tag filters :
53+
```php
54+
$provider = new Geocoder\Provider\Photon\Photon($httpClient, 'https://your-photon-root-url');
55+
$reverseQuery = \Geocoder\Query\GeocodeQuery::create('Paris')
56+
->withData('osm_tag', ['tourism:museum', 'tourism:gallery'])
57+
->withLimit(5);
58+
// Here we get 5 tourism results in Paris which are either museum or art gallery
59+
$results = $provider->reverseQuery($reverseQuery);
60+
```
61+
2062

21-
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or
63+
## Contribute
64+
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or
2265
report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues).

src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_36b7f4cab09652077420062dc53bc340e8b2b22d

Lines changed: 0 additions & 1 deletion
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s:1219:"{"features":[{"geometry":{"coordinates":[13.3879579,52.5185603],"type":"Point"},"type":"Feature","properties":{"osm_id":380498298,"country":"Deutschland","city":"Berlin","countrycode":"DE","postcode":"10117","locality":"Dorotheenstadt","type":"house","osm_type":"N","osm_key":"amenity","housenumber":"151","street":"Friedrichstraße","district":"Mitte","osm_value":"pharmacy","name":"Dorotheenstadt Apotheke"}},{"geometry":{"coordinates":[13.3874475,52.5196854],"type":"Point"},"type":"Feature","properties":{"osm_id":3331787468,"country":"Deutschland","city":"Berlin","countrycode":"DE","postcode":"10117","locality":"Dorotheenstadt","type":"house","osm_type":"N","osm_key":"amenity","housenumber":"25","street":"Georgenstraße","district":"Mitte","osm_value":"pharmacy","name":"Aschenbachs Apotheke"}},{"geometry":{"coordinates":[13.3903812,52.5122639],"type":"Point"},"type":"Feature","properties":{"osm_id":956306643,"country":"Deutschland","city":"Berlin","countrycode":"DE","postcode":"10117","locality":"Dorotheenstadt","type":"house","osm_type":"N","osm_key":"amenity","housenumber":"68","street":"Friedrichstraße","district":"Mitte","osm_value":"pharmacy","name":"Apotheke Q205"}}],"type":"FeatureCollection"}";

src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_61baba2ee6bc4ba2e6688559d40d4e58e1ddd7c1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s:2127:"{"features":[{"geometry":{"coordinates":[-77.0372192,38.9002248],"type":"Point"},"type":"Feature","properties":{"osm_type":"W","osm_id":1049842804,"extent":[-77.0372192,38.9002248,-77.0370581,38.9002243],"country":"United States","osm_key":"highway","city":"Washington","countrycode":"US","osm_value":"secondary","postcode":"20006","name":"H Street Northwest","state":"District of Columbia","type":"street"}},{"geometry":{"coordinates":[-77.0366811,38.9002231],"type":"Point"},"type":"Feature","properties":{"osm_type":"W","osm_id":589539534,"extent":[-77.0370581,38.9002243,-77.0365521,38.9002187],"country":"United States","osm_key":"highway","city":"Washington","countrycode":"US","osm_value":"secondary","postcode":"20006","name":"H Street Northwest","state":"District of Columbia","type":"street"}},{"geometry":{"coordinates":[-77.03689992471391,38.90050395],"type":"Point"},"type":"Feature","properties":{"osm_id":55326891,"extent":[-77.0371738,38.9006934,-77.0367231,38.9003173],"country":"United States","city":"Washington","countrycode":"US","postcode":"20006","locality":"Golden Triangle","type":"house","osm_type":"W","osm_key":"tourism","housenumber":"800","street":"Black Lives Matter Plaza Northwest","osm_value":"hotel","name":"Hay-Adams Hotel","state":"District of Columbia"}},{"geometry":{"coordinates":[-77.0374769,38.9003895],"type":"Point"},"type":"Feature","properties":{"osm_type":"N","osm_id":367142942,"country":"United States","osm_key":"building","city":"Washington","street":"H Street Northwest","countrycode":"US","osm_value":"public","postcode":"20006","name":"United States Chamber of Commerce Building","state":"District of Columbia","type":"house"}},{"geometry":{"coordinates":[-77.0364753,38.9003613],"type":"Point"},"type":"Feature","properties":{"osm_id":4957653991,"country":"United States","city":"Washington","countrycode":"US","postcode":"20062","locality":"Golden Triangle","type":"house","osm_type":"N","osm_key":"tourism","street":"Black Lives Matter Plaza Northwest","osm_value":"information","name":"16th Street Meridian","state":"District of Columbia"}}],"type":"FeatureCollection"}";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}";

0 commit comments

Comments
 (0)