Fix naming of streets on popup
Closed this issue · 5 comments
The MapPopup component uses a hard-coded map of segment names at the moment:
const segmentNames = {
9000002436: 'Dahliastraat',
9000000795: 'Pannestraat',
529611: 'Gasmeterlaan',
9000003002: 'Mimosastraat'
};
This should be replaced by names obtained through the API. I couldn't which Telraam API call provides this API call.
If not available in the Telraam API, an API call can be done to Google APIs, however at a cost of $4/1K calls.
A free API that includes inverse geolocation is positionstack but it doesn't seem to be accurate enough:
➜ curl --location --request POST 'https://telraam-api.net/v1/reports/traffic_snapshot' \
--header "X-Api-Key: $VITE_TELRAAM_API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"time": "live",
"contents": "minimal",
"area": "3.705,51.0696,1"
}' | jq '.features[0] | .geometry.coordinates[0][1]'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5317 100 5193 100 124 5663 135 --:--:-- --:--:-- --:--:-- 5791
[
3.71716455916245,
51.0665482908201
]
Then a call to positionstack with the above coordinates:
➜ curl --location --request GET "http://api.positionstack.com/v1/reverse?access_key=$POSITIONSTACK_API_KEY&query=51.0665482908201,3.71716455916245" \
--header "Content-Type: application/json" | jq '.data[] | .street'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1269 0 1269 0 0 3072 0 --:--:-- --:--:-- --:--:-- 3065
null
"Biervlietstraat"
"Gasmeterlaan"
As we can get the data from the 'traffic' endpoint (although it requires a separate call for each endpoint), we should be fine doing it using this call of hardcoded.
I've started processing the historic data on a separate branch https://github.com/giokara/telraam-bloemekeswijk/compare/feature/conditional-styling...giokara:feature/traffic_snapshot?expand=1 based on your earlier work in https://github.com/stijnvanhoey/telraam-bloemekeswijk/tree/speed-info. This is using the /traffic_snapshot
endpoint, but I couldn't find the street name in the return values. Does the traffic
endpoint return more information?
Good point. I thought the street name was included in the API response of the traffic
or segment by id
call, but I can't reproduce that. Probably my mistake. I propose we stick to the 'hardcoded' way to link the segment id to a street name for now and maintaining it? I can do an update asap for the currently 'undefined'.