deep-jade•2y ago
Google Directions API - timetable information public transportation
Hi guys, I would like to create a timetable information via Google Maps using VF. Which Google API do I need to use (is it the Directions API) How can I correctly integrate the API into Voiceflow?
The Voiceflow user should enter the stop where he would like to get on and then enter the stop where he would like to get off. He also needs to be able to enter the date and time of his trip. After entering this data, Google's timetable information should display the appropriate route in Voiceflow, both as text and as a map.
Is something like that possible? I look forward to your input and thank you in advance for your help!

16 Replies
Yes, this is be doable using Google APIs but you will also need custom components in the react chat to render that in the Chat widget or a dedicated integration if you're thinking of implementing this for another channel.
As an example, here a simple demo generating the instructions from the Google Directions API response and render it using a JS Step and the Text Step with markdown.
jsonData is your Google Directions response from an API Step, then use the {directions} variable in a text step.
You can also use Functions for this.

Great post format @MoveMentor 👏 thanks for posting
deep-jadeOP•2y ago
Thank you NiKo, but as I am a newbie to VF, I need more help, sry!
So, I was able to make an API call to the Google directions API so far, this is the response:
deep-jadeOP•2y ago
deep-jadeOP•2y ago
So, in this API JSON answer, I have a origin (including its place ID) and a destination (also including its place ID).
Now I would like to show the direction from origin to destination in an embadded map including the mode as "transit". How can I integrate my JSON answer into a map?
Thank you so much for your first answer 🙂
The Google Static Maps API does not support specifying the mode of transportation (such as transit) directly in the URL for the map image but you can use the overview_polyline from the API response to generate an image.
https://maps.googleapis.com/maps/api/staticmap?size=600x300&maptype=roadmap&path=enc:${overviewPolyline}&markers=color:green%7Clabel:S%7C${startLocation.lat},${startLocation.lng}&markers=color:red%7Clabel:D%7C${endLocation.lat},${endLocation.lng}&key=${apiKey}
A code example to parse your API response and generate instructions + a link to the map:
{APIResponse} is the variable you map the response from the API step
{instructions} and {mapUrl} the variables you will use to store the value extracted from the API response in your code.
Example:

If instead, you want to use embedded map, then you will have to populate a variable with something like:
and use it in a Text step (this will not render in the Test tool for security reasons, only on the Chat widget).

deep-jadeOP•2y ago
NiKo, amazing, thank you so much for your answer. I would like to use the embedded map as you have shown here in your example. I was working with place ID instead of Lat & Lng. But with place ID it doesn't work. So I think I have to use Lat & Lng, do I? Otherwise would it be possible that you share your example here?
deep-jadeOP•2y ago
So if I'm using the place-ID there is no direction shown...

deep-jadeOP•2y ago
how can I fetch the lng and lat from the API call?
deep-jadeOP•2y ago
this link on the right hand side doesnt work

deep-jadeOP•2y ago
but I fixed the problem with the lat & lng, now I can fetch lat and lng from the api call
deep-jadeOP•2y ago
this works perfectly!

deep-jadeOP•2y ago
but as I wrote before, how can I implement the lat & lng into the embadded map?
thank you so much for helping me in advance
and sorry, one more question: what "lat" and "lng" do I need from the API call? Do I need it from "routes" or from the "start_address" and "end_address"? Here is my JSON API Call:
deep-jadeOP•2y ago