PocketablesGoogleTutorials

Google Home – Location Sharing: ETA & distance

Google Home – Location sharing tutorial sparked a discussion about what other functions could be added to that system. The immediate response was to add the distance and ETA for each contact and this is the follow-up tutorial which will focus on just that. I would strongly recommend you to read the previous article or watch at least the showcase part of the video below.

Google Home – Location Sharing: ETA & distance

The formula is pretty simple. I’m asking Google Home to get me the location of my friend:

Hey Google, Where is Matt?
***Matt is at James st London, UK
Hey Google, Send directions to my phone!
***OK, check your Google Maps
Hey Google, what’s the distance and ETA?
***Matt is currently 200km away, with ETA of 2h and 6 min

In this part, I’m going to take care of the last question. Please bear in mind, that to keep things simple, I’m going to assume, that you are using a Google Home device, not the assistant on your phone. Trying to query the distances on the go, while it’s possible is not within the scope of this tutorial.

To enable the functionality, we will need the help of the IFTTT and Google Maps API. If you followed the previous tutorial, you have almost everything sorted.

IFTTT – ETA and Directions

Manage Applets IFTTT - for some reason we don't have an alt tag hereTo keep things simple, I’m not going to split the information about the distance and the ETA. It’s simple enough to do, I’m sure you will be able to figure it out yourself.  I just need a Google Assistant IFTTT applet liked to the Webhook and configured in the following way:

IF THIS(GOOGLE ASSISTANT)

Commands: What's the distance and ETA
Answer: I'm checking it now for you

THEN THAT (WEBHOOK)

Url: http://NODERED_IP:1880/location/ETA
Method: POST
Content type: application/JSON
Body:

The HTTP POST request needs no data, as we only want to trigger the correct flow. You could ask directly about the distance and ETA without asking for the address, but you have to modify the flow accordingly. I’m trying to introduce as little changes as possible to the previous write-up.

NodeRED – Google Home – Location Sharing: ETA & distance

Node RED callinghome ddns net 1024x213 - for some reason we don't have an alt tag hereThe flow itself is very similar to what I have covered before. We have another Google Maps API link to compose and pass an HTTP GET request. To pass the URL, I’m configuring the function node:

var lat = global.get("locationLat");
var long = global.get("locationLong");
var locationHome = "HomeCoordsLAT,HomeCoordsLONG";

var GoogleKey = "Google Maps API"

msg.url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins="+lat+","+long+"&destinations="+locationHome+"&key="+GoogleKey;
return msg;

Replace the red fields with appropriate values. I’m using stationary coordinates for the Google Home location, you can find them via Google Maps and searching for your location.google home 1024x576 - for some reason we don't have an alt tag here

The URL is saved as msg.url – and passed to the HTTP GET node. I have reversed the destination/origin order, as I believe in most cases I would be interested in the ETA of my friend. If I want ETA to their location, I already have “Send direction to my phone” command. By default, the ETA and distance are calculated as a metric, driving directions. If you want to change it, please check the Google Maps API for the correct variables.

The HTTP GET request returns a string. This string is formatted as  JSON object, and to use it as such, we have to use the JSON node.

Lastly, I have to format the info stored in that JSON object and pass it as the Google Home response:

msg.name = global.get("locationName");
msg.payload.time = msg.payload.rows[0].elements[0].duration.text;
msg.payload.distance =msg.payload.rows[0].elements[0].distance.text;

return msg;

and use the template node

{{name}} is {{payload.distance}} away. The current ETA is {{payload.time}}

And pass it over to the Google Home node! There you have it!

Conclusion

You can see how to obtain the information about the distance and ETA. You can modify the entire set up to give you that information independently, but in this tutorial, you have to query the address first to have the access to the distance and the ETA. I hope you find this helpful!  Let me know what do you think about it! If you want to use ready made files, please click here for the file download. I write for pocketables.com for free, if you enjoy my content you can buy me a coffee via PayPal or join one of Patreon Rewards tiers.

Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!
Become a patron at Patreon!

Mat Zolnierczyk

I am passionate about technology, cycling, and art. This would explain why my bike has more computing power than your average office. I own notenoughtech.com and I write for xda-developers.com and pocketables.com NotEnoughTECH | Facebook | Twitter |YouTube |Instagram | Google+ |Donate |Patreon

Avatar of Mat Zolnierczyk