geocoder-php / geocoder-php/Geocoder
GeocodeQuery WithBounds not strictly used across providers that support it
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- PHP
- Sterne
- 4k
- Forks
- 525
- Ø Merge
- 8 Min.
- Gemergte PRs (30 T.)
- 1
Beschreibung
The WithBounds logic needs to be added to providers, as the method is a base method in the query.
E.g. in Nominatims provider we see:
$viewbox = $query->getData('viewbox');
if (!is_null($viewbox) && is_array($viewbox) && 4 === count($viewbox)) {
$url .= '&'.http_build_query([
'viewbox' => implode(',', $viewbox),
], '', '&', PHP_QUERY_RFC3986);
$bounded = $query->getData('bounded');
if (!is_null($bounded) && true === $bounded) {
$url .= '&'.http_build_query([
'bounded' => 1,
], '', '&', PHP_QUERY_RFC3986);
}
}
The above should instead or in-addition accept $query->getBounds(), because otherwise it forces us to write code like:
// Bounds of EU/UK where our customers are
$euBounds = new Bounds(34.857764, -30.428009, 75.400203, 41.642303);
$geocodeQuery = GeocodeQuery::create($query)
->withBounds($euBounds)
// For Nominatim
->withData('viewbox', $euBounds->toArray());
Pelias Providers and those that extend it don't support it at all -even though Pelias does:
https://github.com/pelias/documentation/blob/master/search.md#search-within-a-rectangular-region
/**
* @param array<string, mixed> $query_data additional query data (API key for instance)
*
* @throws \Geocoder\Exception\Exception
*/
protected function getGeocodeQueryUrl(GeocodeQuery $query, array $query_data = []): string
{
$address = $query->getText();
// This API doesn't handle IPs
if (filter_var($address, FILTER_VALIDATE_IP)) {
throw new UnsupportedOperation(sprintf('The %s provider does not support IP addresses, only street addresses.', $this->getName()));
}
$data = [
'text' => $address,
'size' => $query->getLimit(),
'layers' => null !== $query->getData('layers') ? implode(',', $query->getData('layers')) : null,
'boundary.country' => null !== $query->getData('boundary.country') ? implode(',', $query->getData('boundary.country')) : null,
];
return sprintf('%s/search?%s', $this->root, http_build_query(array_merge($data, $query_data)));
}
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die bestehende Behandlung von viewbox und bounded beim Nominatim-Provider zu untersuchen, und verfolge anschließend die Pelias-Provider durch getGeocodeQueryUrl. Vergleiche, wie GeocodeQuery getBounds() bereitstellt, mit den von jedem Provider unterstützten Request-Parametern. Erledigt ist die Aufgabe, wenn Provider, die rechteckige Grenzen unterstützen, konsistent die Query-Grenzen verwenden, ohne doppelte provider-spezifische Daten zu benötigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- php
- Bereich
- api, backend
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100