Calculate Distances in WhatsApp

Abby Updated by Abby

In the case that we want to calculate the distance between two coordinates in WhatsApp

We can use the Google Distance Matrix API if you already have a Google Cloud account, you can simply import this to your project, by selecting 'enable'

If you don't yet have a Google Cloud account here's how you can create one

The Flow:

User View:

Collecting Coordinates:

We'll use two address blocks to collect both the origin and the destination

In the first address block we'll save the variable as 'origin'

In the second address block, we'll save it as 'destination'

Webhook Block:

Next we'll need a webhook block, with a GET request to the following endpoint:

https://maps.googleapis.com/maps/api/distancematrix/json

In the params we'll enter 'origins' as the key and @origin as the value

We'll then enter 'destinations' as another key and @destination as the value

Finally we'll enter 'key' as the key and our API key as the value

Test the Request:

To test the request we can enter LAT & LONG separated by commas(an easy way to get these if from Google Maps url)

The Response:

We should expect this response:

The value we want to save is on line 13

We'll select the purple drop down and save this line as a String type variable

Then optionally we can display this to the user (I saved the variable here as @distance):

How did we do?

Trigger Event if User Abandons Chat

Customized Behavior in Mobile Browsers

Contact