geocoder-php / geocoder-php/Geocoder
GeocodeQuery WithBounds not strictly used across providers that support it
Nessuno ha ancora preso questa issue.
- Lingua principale
- PHP
- Stelle
- 4k
- Fork
- 525
- Merge medio
- 8m
- PR unite (30g)
- 1
Descrizione
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)));
}
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando la gestione esistente di viewbox e bounded nel provider Nominatim, quindi segui i provider Pelias attraverso getGeocodeQueryUrl. Confronta il modo in cui GeocodeQuery espone getBounds() con i parametri di request supportati da ciascun provider. Il lavoro è completato quando i provider che supportano limiti rettangolari utilizzano coerentemente i limiti della query senza richiedere dati specifici del provider duplicati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- php
- Ambito
- api, backend
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100