shi ft
shi ft

Reputation: 19

how to get traffic data using api

Hi I am working on a project that needs traffic data I am trying to use APIs like tomtom or HERE but i can't get it to work

All I want is to collect the traffic count (number of cars in each route) and stock it in pandas df

I tried this but it didn't give me traffic count

response = requests.get('https://api.tomtom.com/traffic/services/4/incidentDetails/s3/-35.871247%2C140.910645%2C-28.902397%2C153.566895/22/-1/json?key='+apiKey+'&projection=EPSG4326&originalPosition=true')
dict = json.loads(response.content)
print(dict)
keys = dict.keys() 
values = dict.values()

I can use any other api instead of tomtom if it can provide data too

Upvotes: 0

Views: 1343

Answers (3)

Taif Alomar
Taif Alomar

Reputation: 1

To get the number of cars (samples) within a route, you can use either Traffic Stats API or O/D Analysis from TomTom. but you need a custom payment for it. you can have a free trial for only a month using the Move portal but it's pretty limited in terms of date range available and number of reports you can make. regarding HERE's, I explored that before and they don't provide the number of cars at all. if someone has a better experience using these services I hope they can add more on this.

Upvotes: -1

szogoon
szogoon

Reputation: 644

Those services do not return number of cars.

Upvotes: 0

Wizard.Ritvik
Wizard.Ritvik

Reputation: 11670

Try this here code:

from json import dumps as to_json_func_from_the_json_module

from requests import get

key = 'tada!'
response = get(f'https://api.tomtom.com/traffic/services/4/incidentDetails/s3/-35.871247%2C140.910645%2C-28.902397%2C153.566895/22/-1/json?{key=!s}&projection=EPSG4326&originalPosition=true')
dct = response.json()

print(to_json_func_from_the_json_module(dct, indent=2, default=str))
print('N. (#) Keys:', len(dct))

It should work. Let me know if not.

Upvotes: 0

Related Questions