Hi. I’m a total newbie to the TomTom traffic api but I need to get it working for a fun little web project that changes a website’s colour based on traffic flow. I’ve setup a key and followed the documentation to put together an API URL. I’m getting this error though:
‘Error fetching traffic data: TypeError: Cannot read properties of undefined (reading ‘freeFlowSpeed’)’
It’s at this line in my code:
` const trafficStatus = jsonData.flowSegmentData.freeFlowSpeed;`
Can anyone help get me past this issue?
Quick update, I got this working but not with the coordinates that I need it to. If I use the coordinates given in the example on the documentation page it works, but when I put the coordinates in for the location I need it breaks. I’ve separated them with a comma as instructed in the docs:
Any suggestions on how to get those coordinates working?
Further update. Using the API explorer I tested the coordinates and got this message:
"error": "Point too far from nearest existing segment.",
"message": "Point too far from nearest existing segment."
The coordinates are for the UK, which is covered in TomTom’s traffic flow coverage
The API requires coordinates in latitude,longitude format.
Thanks, I had just figured this out myself. The website I was using to get coordinates outputted them longitude,latitude. Thanks, it’s working nicely now.
I’m picking this up again because I don’t think the data I’m getting is accurate. Over the past month every single time I’ve checked the data the traffic flow speed is either 47 or 49, not once has it been anything different. I’ve even checked when I can see the motorway in question, which a couple times has either been at a standstill or closed entirely due to a flood, the flow speed was still 49. I’m a total beginner with this, but is there a way to get more accurate information on flow speed? Or are there big limitations to the accuracy of the data?