Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapbox Provider prevents searching for countries #1107

Open
randriese opened this issue Jan 15, 2021 · 2 comments
Open

Mapbox Provider prevents searching for countries #1107

randriese opened this issue Jan 15, 2021 · 2 comments

Comments

@randriese
Copy link

randriese commented Jan 15, 2021

I'm using the Mapbox Provider in my API to fetch coordinates for given entities. These entities can be either:

  • Countries
  • Cities
  • Districts
  • Addresses

However, the current implementation of the mapbox provider prevents from returning anything that doesn't contain a context.

When I run this snippet and watch the console, I see that the query to Mapbox is correct and data is returned.
$locations = $mapboxGeocoder->geocodeQuery(
GeocodeQuery::create($country->getName())
->withLocale('nl')
->withData('location_type', 'country')
);

However, the fetchUrl method in Mapbox.php simply breaks when a result without context is returned by Mapbox.
https://github.com/geocoder-php/mapbox-provider/blob/master/Mapbox.php#L283

When I remove that piece of code, and add an additional check here to check if context is available before iterating through it, the code returns the requested items.
https://github.com/geocoder-php/mapbox-provider/blob/master/Mapbox.php#L301

This isn't a clean solution and additional models are required to make it a better implementation. However, the repo is read-only so I cannot help with the required changes

@jbelien
Copy link
Member

jbelien commented Jan 15, 2021

This isn't a clean solution and additional models are required to make it a better implementation. However, the repo is read-only so I cannot help with the required changes

You can submit a PR in our main repository (this one).
Mapbox provider is located here: https://github.com/geocoder-php/Geocoder/tree/master/src/Provider/Mapbox

@randriese
Copy link
Author

It seems that quite a big PR is required for the library to support Countries, Cities or Districts as valid query results...
I'll see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants