mapbox / mapbox/mapbox-gl-geocoder

422 Error When Using External Geocoder and Mapbox GL JS

Open
#496 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged needs information
Dominant language
JavaScript
Stars
388
Forks
181
PR merge metrics
No merged PRs in 30d

Description

1. I am using an external geocoder with the Mapbox geocoder widget.
2. The results return and are concatenated to the standard geocoder results correctly.
3. When clicking on a result in the geocoder tool menu, it navigates correctly to the point identified in the list.
4. *It also throws a 422 error, and I am not sure why.*

This is the code where I implement it:

```js
externalGeocoder: async (queryString) => {
const filters = {
geom_column: 'geom',
filter: `cast(busstopid as text) like '${queryString}%' or address like upper('${queryString}%')`,
precision: 9,
columns: 'address as place_name, address as text, busstopid',
id_column: 'internal_id',
limit: 5,
};
// get data from both the GTFS feed and MIIPS if possible
const generalData = await utilities.getData(`${URL.base}/v1/geojson/gtfs_data?`, filters);
const miipsData = await utilities.getData(
`${URL.base}/mama/miips/read_serial_number_geocoder/${queryString}`
);

if (miipsData.features) {
return generalData.features.concat(miipsData.features);
} else {
return generalData.features;
}
}
```

This is the object the external geocoder is creating:

```json
{
"type": "FeatureCollection",
"features": [
{
"id": 13419,
"type": "Feature",
"center": [
-73.94012,
40.765427
],
"geometry": {
"type": "Point",
"coordinates": [
-73.94012,
40.765427
]
},
"place_name": "34 AV/VERNON BL",
"properties": {
"text": "34 AV/VERNON BL",
"busstopid": 552207,
"place_name": "34 AV/VERNON BL"
}
},
{
"id": 14304,
"type": "Feature",
"center": [
-74.107189,
40.671472
],
"geometry": {
"type": "Point",
"coordinates": [
-74.107189,
40.671472
]
},
"place_name": "34 ST/HOBOKEN LIGHT RAIL STATION",
"properties": {
"text": "34 ST/HOBOKEN LIGHT RAIL STATION",
"busstopid": 805054,
"place_name": "34 ST/HOBOKEN LIGHT RAIL STATION"
}
},
{
"id": 14305,
"type": "Feature",
"center": [
-74.10723,
40.671416
],
"geometry": {
"type": "Point",
"coordinates": [
-74.10723,
40.671416
]
},
"place_name": "34 ST/HOBOKEN LIGHT RAIL STATION",
"properties": {
"text": "34 ST/HOBOKEN LIGHT RAIL STATION",
"busstopid": 805056,
"place_name": "34 ST/HOBOKEN LIGHT RAIL STATION"
}
}
]
}
```

I looked into the repo and tried to discern from the error and payload what I was doing wrong. The results seem to work correctly, but it also seems like it is trying to use the external result with the standard geocoder somehow, which seems wrong. I am not sure how to drill down into this further to better diagnose the behavior, but any help would be most appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the externalGeocoder callback and the supplied FeatureCollection, then trace the result-selection path used when a returned feature is clicked. Reproduce the 422 with the shown payload and inspect whether selection also invokes the standard geocoder request. Done means identifying the request causing the 422 and documenting or correcting the handling of external results.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.