Google Maps Distance Matrix
For AppInventor & Makeroid Apps
Description
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.makeroid.io/distance-matrix/
- (http://scripts.makeroid.io/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
-
?distance_matrix
Compulsory
This will init the script and call the basic functions
eg.: http://scripts.makeroid.io/distance-matrix/?distance_matrix -
&origin
Compulsory
This will allow you to setup the origin coordinates-
&a_lat=
Compulsory
Setup your origin latitude
eg.: http://scripts.makeroid.io/distance-matrix/?distance_matrix&origin&a_lat=42.8265457 -
&a_lon=
Compulsory
Setup your origin longitude
eg.: http://scripts.makeroid.io/distance-matrix/?distance_matrix&origin&a_lon=-8.6052464
-
-
&destination
Compulsory-
&z_lat=
Compulsory
Setup your destination latitude
eg.: http://scripts.makeroid.io/distance-matrix/?distance_matrix&destination&z_lat=42.8389455 -
&z_lon
Compulsory
Setup your destination longitude
eg.: http://scripts.makeroid.io/distance-matrix/?distance_matrix&destination&z_lon=-8.5833596
-
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.makeroid.io/distance-matrix/?distance_matrix&origin&a_lat=42.8265457&a_lon=-8.6052464&destination&z_lat=42.8389455&z_lon=-8.5833596
-
language
Default one isen-GB
Use your custom language for results. Choose one of these: -
&mode=
Default one isdriving
Set how do you move. Choose one of these:-
driving
Transport by car -
walking
Walk -
bicycling
Transport by bike -
transit
Use public transport (see&transit_mode
for more info)_
eg.: http://scripts.makeroid.io/distance-matrix/?distance_matrix&mode=bicycling
-
-
&avoid=
Default one isnull
Avoid some facilities. Choose how many as you want:-
tolls
Avoid tolls from route -
highways
Avoid highways -
ferries
Avoid ferries -
indoor
Avoid indoor routes
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&avoid=tolls,ferries
-
-
&units=
Default one ismetric
Setup your result’s units. Choose one of these:-
metric
Use metric and decimal system -
imperial
Use imperial system
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&units=imperial
-
-
&departure_time
Default one isnow
Setup departure time in seconds starting from 1 January 1970 (UTC) - Checkout alternative time units in Time Calculator
Useful only if&mode=transit
and if&arrival_time
is not set
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&departure_time=1486338119 -
&departure_time
Default one isnull
Setup arrival time in seconds starting from 1 January 1970 (UTC) - Checkout alternative time units in Time Calculator
Useful only if&mode=transit
and if&departure_time
is not set
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&departure_time=1486338119 -
&conditions
_Default one isbest_guess
Setup traffic conditions in route. Choose one of these:-
best_guess
Use current traffic conditions -
optimistic
Use the best traffic conditions -
pessimistic
Use the worst traffic conditions
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&conditions=pessimistic
-
-
&transit_mode
Default one isbus
Setup how do you want to move.
Useful only if&mode=transit
. Choose how many as you want:-
bus
Enable bus transit -
subway
Enable subway transit -
train
Enable train transit -
tram
Enable tram transit -
rail
Enable railway transit
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&transit_mode=train,rail,tram
-
-
&transit_prefs
_Default one isless_walking
Setup the preference of transit mode
Useful only if&mode=transit
. Choose one of these:-
less_walking
Use as many transport as you can -
fewer_transfers
Prefer one transport instead of two
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&transit_prefs=fewer_transfers
-
You can join all of this parameters (except some of them that have already been already marked)
Handle response
-
To get the time between those places, add to the url:
&need&get_time
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&need&get_time -
To get the distance between those places, add to the url:
&need&get_distance
eg.: https://scripts.makeroid.io/distance-matrix/?distance_matrix&need&get_distance
Use it yourself
Use your own API Key
Add this parameter to use your own API Key: &custom_key=
eg.: https://scripts.makeroid.io/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