Mapbox: support the new Geocoding v6 API
Summary
The current Mapbox lookup (lib/geocoder/lookups/mapbox.rb) uses the Geocoding v5 API:
https://api.mapbox.com/geocoding/v5/{dataset}/{query}.json
Mapbox has released the Geocoding v6 API, and v5 is now documented as the "previous version". While v5 still works for address/place searches, it is effectively in legacy status:
- POI data has been removed from v5 (users are directed to the Search Box API).
- New features are only available in v6: unit-level geocoding, structured input, Smart Address Match, improved batch geocoding (same per-request price as v5).
API differences
v6 changes both the endpoints and the response format, so it cannot be supported by just swapping the URL:
| v5 | v6 | |
|---|---|---|
| Forward | GET /geocoding/v5/{dataset}/{query}.json |
GET /search/geocode/v6/forward?q={query} |
| Reverse | GET /geocoding/v5/{dataset}/{lon},{lat}.json |
GET /search/geocode/v6/reverse?longitude={lon}&latitude={lat} |
| Permanent storage | separate dataset (mapbox.places-permanent) |
permanent=true parameter |
| Response | feature with place_name, text, flat context array keyed by id prefix |
feature with properties.full_address, properties.name, structured properties.context object (country, region, place, postcode, street, address, ...) |
Because the response structure is different, Geocoder::Result::Mapbox (which parses place_name / text / context[].id) does not work with v6 responses.
Proposal
Add a new :mapbox_v6 lookup (with its own result class) alongside the existing :mapbox lookup, following the same pattern as other versioned lookups. This keeps existing users on v5 unaffected while allowing opt-in to v6.
I'm happy to submit a PR for this if the approach sounds reasonable.
References
- Geocoding v6 docs: https://docs.mapbox.com/api/search/geocoding/
- Geocoding v5 docs (previous version): https://docs.mapbox.com/api/search/geocoding-v5/