Distance Matrix



Google Maps Distance Matrix

For AppInventor & Thunkable Apps


This script will allow you to get the travel distance between two points using Google Maps Matrix Distance API.
It allows you to setup all GoogleMaps Trave parameters, like transport method or departure time.

How to use it

To use the script, you will need to setup a WebComponent in your AppInventor project, and disable SaveResponse checkbox and leave blank the URL
Then, in blocks screen, init a variable called base_url with the value https://scripts.thunkable.ga/google/maps/distance-matrix/ - (http://scripts.thunkable.ga/google/maps/distance-matrix/)
And then, you can setup parameters to that variable using the block join(Text) like ?distance-matrix to customize the script

Customization Parameters

With those params you can use this script, but continue reading if you want more customization. So, a basic usage example would be: http://scripts.thunkable.ga/google/maps/distance-matrix/?distance_matrix&origin&a_lat=42.8265457&a_lon=-8.6052464&destination&z_lat=42.8389455&z_lon=-8.5833596

If you need help finding your coordinates, use this website Get Coordinates
Or without graphical interface: https://scripts.thunkable.ga/google/maps/coordinates/?coordinates&location&country=your_country&province=your_state&city=your_city&street=your_street&need&longitude or https://scripts.thunkable.ga/google/maps/coordinates/?coordinates&location&country=your_country&province=your_state&city=your_city&street=your_street&need&latitude using GoogleMaps API

You can join all of this parameters (except some of them that have already been already marked)

Handle response

Use it yourself

Use your own API Key

Add this parameter to use your own API Key: &custom_key=
eg.: https://scripts.thunkable.ga/google/maps/distance-matrix/?distance_matrix&custom_key=your_matrix_key

You can request one here:
Google Maps -> Distance Matrix API -> Google Developers Console

Source Code

SourceCode is avaliable on GitHub:
Distance Matrix


Estimated time between two locations Google Maps
Tomar distancia y tiempo de Google maps
How to make a google map 'navigation'
Google maps and MIT App inventor
Calculate estimated time to destination
Calculate distance
How to compare a big list of numbers?

Sorry, I forgot to add how to handle the answer
Tomorrow I will add it to the post

A rapid usage will be adding &need&get_time or &need&get_distance


Where is variable called base_url? i can’t find it! can you do and a video tutorial?
Thanx for your time.


Initialize a new variable called base_url, and jpin a text block with the base url


i have this and it only outputs the url, it says in the tutorial thast you have to activate webcomponent but how do you do that?


Add a web component, set the URL to that text (also, don’t forgot to add &origin and &destination variables in URL) and call Web1 Get


im sorry im asking so many questions but is a webcomponent a block? because if it is, i cant seem to find it…


In Connectivity Section, in Designer screen, there is a WebComponent object


stil can’t find it… where is the connectivity section?
nvm, found it… it was in the designer section instead of the blocks section -_-


when i get this to work im gonna be so happy but i added the web component, called it in and added the base url to the “url” section of thhe webcomponent and i still only get to see the url?



first of all i want to say thank you for all your help so far but why doesnt this work?

i put the base url in the webcomponent’s url


You can’t do it like that

Let me make a small example

  • initialize global base_url - Inits the web url
  • when Button1 Click - Handle the action
    • set Web1 Url to + join - Setup the web URL
    • call Web1 Get - Make the request to the URL
  • when Web1 Got Text - Handle the request
    set Label1 Text to + responseContent - Set the label text to the answer


It worked! Thank you so much for all your help :smiley:


I get only a html doc that tells me “Moved Permantly the document has moved here” what i doing wrong?


Can you send your blocks?


i fix the moved permantly but now it tells me add &distance_matrix to init the script.


In the join(Text) block, you tipped ?distance-matrix instead of ?distance_matrix


and if i wanna have multiple calculations on one svreen i jusnt make multiple web components?


With one component is enough

Change the Web URL for each request, and then handle the request with the same block