GeocodeQuery WithBounds not strictly used across providers that support it
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by inspecting the Nominatim provider's existing viewbox and bounded handling, then trace the Pelias providers through getGeocodeQueryUrl. Compare how GeocodeQuery exposes getBounds() with each provider's supported request parameters. Done means providers that support rectangular bounds consistently use the query bounds without requiring duplicated provider-specific data.
Written by the indexing model from the issue text.
Description
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)));
}
- Dominant language
- PHP
- Stars
- 4k
- Forks
- 525
- Avg merge
- 8m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from geocoder-php/Geocoder
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
geocoder-php/Geocoder#1272 ·
-
question
Difficulty 4/5 3-5 days Newbie friendliness 25/100
geocoder-php/Geocoder#1267 · 2 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 38/100
geocoder-php/Geocoder#1244 · 2 comments · 2 reactions ·
-
provider
Difficulty 4/5 3-5 days Newbie friendliness 30/100
geocoder-php/Geocoder#1243 ·
-
Mapbox Geocoding v6 Openprovider
Difficulty 4/5 3-5 days Newbie friendliness 35/100
geocoder-php/Geocoder#1237 · 1 comment · 1 reaction ·
All issues in geocoder-php/Geocoder
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·