-
1Get a free Google Maps API key
To get the live traffic data you need to use an individual API key from Google Maps. This is free and easy to get: Go to this page and klick the button "Get a Key": https://developers.google.com/maps/documentation/distance-matrix .
-
2Generate a HTTP request
The HTTP request should contain the individual start address, destination address and your private API key. As a starting point you can try this example in combination with your key:
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&departure_time=now&traffic_model=best_guess&key=YOUR_API_KEY
By inserting this line in the browser URL field you should get the estimated time of arrival and the distance for the requested route in the JSON format. If this works fine just replace the origins and destination address with your own examples. Great!
-
3Generate a Particle Webhook
At Particle's Console in the Web IDE, following the section "Integration" and "New Integration" we can generate a new Webhook via Browser IDE by selecting "Webhook".
Event Name = TrafficIndicator (or anything else you'd like to use in the sketch lateron)
URL = (the above generated & tested HTTP request string)
Request Type = GET
Device = (Your device name)
Response Template = {{origin_addresses}}~{{destination_addresses}}~{{#rows}}{{#elements}}{{distance.text}}~{{duration_in_traffic.text}}{{/elements}}{{/rows}}
Include Default Data = Yes
Enforce SSL = Yes
(Remaining fields can be left blank)
-
4Run the sketch
Open the attached INO sketch. Then add the two libraries as described in the sketch and verify that the name of the webhook is inserted correctly. Compile & run the sketch!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Since the Google Maps team slightly updated their API I slightly updated the syntax of the http-request in the instruction above. Now its working again, thanks to Michael for the hint!
Are you sure? yes | no