Google Maps API/jsonDecode

90 views
Skip to first unread message

cfa.h...@gmail.com

unread,
Jan 8, 2018, 2:13:45 PM1/8/18
to Automate
Hi, love the app! I'm currently using it to automatically answer specific SMS and it's working great!

I want to upgrade my flow so that instead of just automatically answering the SMS, that it instead displays a dialog window with some information which I later confirm or decline.

The text messages themselves have locations and times that I would like to use in a function that tells me in a dialog window how long it will take me to get there at the given times.
I am looking into Google Maps API which incidentally returns a JSON or XML. Since there is a jsonDecode function, I thought I'd give it a go.

I've gotten everything basically figured out except how Automate downloads the JSON and how to then "decode" it (extracting values and loading them into variables).

Any tips?

Some feedback:
I really love the app. I am a hobby programmer and find everything really interesting. Although, I find it difficult to figure out how some things work. I usually prefer to use examples and implement them into my own products. That is how I learn.
The documentation on the website/in the app doesn't include this. I would really love to see some examples of different types of uses of functions, explicitness if an argument is optional, and what different types as arguments in syntax looks like.

Again, love the app!
Thanks to anyone with some tips!

Henrik "The Developer" Lindqvist

unread,
Jan 8, 2018, 2:40:16 PM1/8/18
to Automate
  1. HTTP request: Response content (output variable) = response
  2. Variable set: response = jsonDecode(response)
  3. Access the response variable as described in the Google Maps API docs.

cfa.h...@gmail.com

unread,
Jan 8, 2018, 2:43:44 PM1/8/18
to Automate
Tack så mycket för hjälpen!

cfa.h...@gmail.com

unread,
Jan 8, 2018, 2:55:59 PM1/8/18
to Automate
I'm looking for instructions on how to parse the json response but to no avail. I don't suppose you would mind giving me one example as to how it's use would look like in a block? Maybe I can figure the rest out from one example.

Thanks again!

Henrik "The Developer" Lindqvist

unread,
Jan 8, 2018, 3:16:21 PM1/8/18
to Automate
The following example has some JSON API calls:
http://llamalab.com/automate/community/flows/5374

cfa.h...@gmail.com

unread,
Jan 8, 2018, 6:29:10 PM1/8/18
to Automate
Thanks again for the quick responses.
The flow you linked does not show any examples of accessing nested json variables.. For example

{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"partial_match" : true,
"place_id" : "EidQZXBwYXJnYXRhbiAyOSwgNzAyIDE4IMOWcmVicm8sIFN2ZXJpZ2U",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJt7MNC5kUXEYRNsOKXrmRl2M",
"types" : [ "establishment", "point_of_interest", "school" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 59.25292899999999,
"lng" : 15.2162169
},
"southwest" : {
"lat" : 59.2394792,
"lng" : 15.1854676
}
},
"copyrights" : "Kartdata ©2018 Google",
"legs" : [
{
"distance" : {
"text" : "2,9 km",
"value" : 2928
},
"duration" : {
"text" : "37 min",
"value" : 2248
},
"end_address" : "Halltorpsvägen 11-13, 701 35 Örebro, Sverige",
"end_location" : {
"lat" : 59.2394792,
"lng" : 15.1854676
},
"start_address" : "Peppargatan 29, 702 18 Örebro, Sverige",
"start_location" : {
"lat" : 59.25292899999999,
"lng" : 15.2162169
},
"steps" : [
{
"distance" : {
"text" : "2,9 km",
"value" : 2928
},
"duration" : {
"text" : "37 min",
"value" : 2248
},
"end_location" : {
"lat" : 59.2394792,
"lng" : 15.1854676
},
"html_instructions" : "Gå till Halltorpsvägen 11-13, 701 35 Örebro, Sverige",
"polyline" : {
"points" : "yyshJk|z{AdBR?FE|BElAAx@C|@@n@AfB@nA@lBBdB@fC@bA?JBnAB|ABx@@x@@j@@b@?\\?RANJtEJjFD`CHzBBj@Fj@TtA~@rEBPd@xB?HB~AFbDHxD?JHtEJnFB`@?`@BP?@H\\L`@N^T`@@NBB\\~@?F@B?B@B?B@B@B@B@@@@B@@@@?B?@AB?@Ab@ZD?D?@?VVDHDL?B?HANEl@O~@Kx@CRAJ?D@F@BFBJBP?PKPELEDAPCTARDXHn@NLD^VF@^Br@Tf@^l@b@dAp@RTPZZ|@l@jCTl@Vb@PPLHNBV@j@Fx@Zn@Et@Kj@Eb@Gx@Qd@I^Et@BH@L@ND`@Pv@Fn@@jA_@l@[F\\Fl@@ZNxCRzE@X?@DA\\C?FDH@DFv@Hh@FVNTPXBdHd@M`@EVC@?ZC|@BVAX?f@AD?ZFVJVNFJJLFLHTL\\BHJf@Fl@Br@@rAZZFLDP"
},
"start_location" : {
"lat" : 59.25292899999999,
"lng" : 15.2162169
},
"steps" : [
{
"distance" : {
"text" : "57 m",
"value" : 57
},
"duration" : {
"text" : "1 min",
"value" : 41
},
"end_location" : {
"lat" : 59.2524198,
"lng" : 15.2161212
},
"html_instructions" : "Gå mot \u003cb\u003esöderut\u003c/b\u003e på \u003cb\u003ePeppargatan\u003c/b\u003e mot \u003cb\u003eKarlsdalsallén\u003c/b\u003e",
"polyline" : {
"points" : "yyshJk|z{AdBR"
},
"start_location" : {
"lat" : 59.25292899999999,
"lng" : 15.2162169
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,8 km",
"value" : 778
},
"duration" : {
"text" : "10 min",
"value" : 574
},
"end_location" : {
"lat" : 59.2514714,
"lng" : 15.202833
},
"html_instructions" : "Sväng \u003cb\u003ehöger\u003c/b\u003e till \u003cb\u003eKarlsdalsallén\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "svshJw{z{A?FE|BElAAx@C|@@n@AfB@nA@lBBdB@fC@bA?JBnAB|ABx@@x@@j@@b@?\\?RANJtEJjFD`CHzBBj@Fj@TtA~@rEBPd@xB"
},
"start_location" : {
"lat" : 59.2524198,
"lng" : 15.2161212
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,3 km",
"value" : 273
},
"duration" : {
"text" : "3 min",
"value" : 200
},
"end_location" : {
"lat" : 59.25123499999999,
"lng" : 15.1980474
},
"html_instructions" : "Fortsätt in på \u003cb\u003eGolfbanevägen\u003c/b\u003e",
"polyline" : {
"points" : "upshJuhx{A?HB~AFbDHxD?JHtEJnFB`@"
},
"start_location" : {
"lat" : 59.2514714,
"lng" : 15.202833
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "66 m",
"value" : 66
},
"duration" : {
"text" : "1 min",
"value" : 49
},
"end_location" : {
"lat" : 59.25090269999999,
"lng" : 15.1971315
},
"html_instructions" : "Fortsätt rakt fram till \u003cb\u003eStenbackevägen\u003c/b\u003e",
"maneuver" : "straight",
"polyline" : {
"points" : "eoshJyjw{A?`@BP?@H\\L`@N^T`@"
},
"start_location" : {
"lat" : 59.25123499999999,
"lng" : 15.1980474
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "32 m",
"value" : 32
},
"duration" : {
"text" : "1 min",
"value" : 30
},
"end_location" : {
"lat" : 59.2507201,
"lng" : 15.1967123
},
"html_instructions" : "Svag sväng \u003cb\u003ehöger\u003c/b\u003e för att fortsätta på \u003cb\u003eStenbackevägen\u003c/b\u003e",
"maneuver" : "turn-slight-right",
"polyline" : {
"points" : "cmshJaew{A@NBB\\~@"
},
"start_location" : {
"lat" : 59.25090269999999,
"lng" : 15.1971315
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "1,1 km",
"value" : 1060
},
"duration" : {
"text" : "14 min",
"value" : 861
},
"end_location" : {
"lat" : 59.24272,
"lng" : 15.192369
},
"html_instructions" : "I rondellen tar du \u003cb\u003e3:e\u003c/b\u003e avfarten in på \u003cb\u003eSommarrovägen\u003c/b\u003e",
"maneuver" : "roundabout-right",
"polyline" : {
"points" : "_lshJmbw{A?F@B?B@B?B@B@B@B@@@@B@@@@?B?@AB?@Ab@ZD?D?@?VVDHDL?B?HANEl@O~@Kx@CRAJ?D@F@BFBJBP?PKPELEDAPCTARDXHn@NLD^VF@^Br@Tf@^l@b@dAp@RTPZZ|@l@jCTl@Vb@PPLHNBV@j@Fx@Zn@Et@Kj@Eb@Gx@Qd@I^Et@BH@L@ND`@Pv@Fn@@jA_@l@["
},
"start_location" : {
"lat" : 59.2507201,
"lng" : 15.1967123
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,1 km",
"value" : 148
},
"duration" : {
"text" : "2 min",
"value" : 112
},
"end_location" : {
"lat" : 59.24244330000001,
"lng" : 15.1898401
},
"html_instructions" : "Sväng \u003cb\u003ehöger\u003c/b\u003e till \u003cb\u003eGlomman\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "_zqhJigv{AF\\Fl@@ZNxCRzE@X?@"
},
"start_location" : {
"lat" : 59.24272,
"lng" : 15.192369
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "20 m",
"value" : 20
},
"duration" : {
"text" : "1 min",
"value" : 27
},
"end_location" : {
"lat" : 59.24225970000001,
"lng" : 15.1898723
},
"html_instructions" : "Sväng \u003cb\u003evänster\u003c/b\u003e mot \u003cb\u003eHalltorpsvägen\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "gxqhJowu{ADA\\C"
},
"start_location" : {
"lat" : 59.24244330000001,
"lng" : 15.1898401
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "9 m",
"value" : 9
},
"duration" : {
"text" : "1 min",
"value" : 6
},
"end_location" : {
"lat" : 59.24221559999999,
"lng" : 15.1897513
},
"html_instructions" : "Sväng \u003cb\u003ehöger\u003c/b\u003e mot \u003cb\u003eHalltorpsvägen\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "cwqhJuwu{A?FDH@D"
},
"start_location" : {
"lat" : 59.24225970000001,
"lng" : 15.1898723
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,1 km",
"value" : 144
},
"duration" : {
"text" : "2 min",
"value" : 102
},
"end_location" : {
"lat" : 59.2418975,
"lng" : 15.1874339
},
"html_instructions" : "Svag sväng \u003cb\u003ehöger\u003c/b\u003e mot \u003cb\u003eHalltorpsvägen\u003c/b\u003e",
"maneuver" : "turn-slight-right",
"polyline" : {
"points" : "{vqhJ}vu{AFv@Hh@FVNTPXBdH"
},
"start_location" : {
"lat" : 59.24221559999999,
"lng" : 15.1897513
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "0,3 km",
"value" : 311
},
"duration" : {
"text" : "4 min",
"value" : 224
},
"end_location" : {
"lat" : 59.23968980000001,
"lng" : 15.1857688
},
"html_instructions" : "Sväng \u003cb\u003evänster\u003c/b\u003e till \u003cb\u003eHalltorpsvägen\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "{tqhJmhu{Ad@M`@EVC@?ZC|@BVAX?f@AD?ZFVJVNFJJLFLHTL\\BHJf@Fl@Br@@rA"
},
"start_location" : {
"lat" : 59.2418975,
"lng" : 15.1874339
},
"travel_mode" : "WALKING"
},
{
"distance" : {
"text" : "30 m",
"value" : 30
},
"duration" : {
"text" : "1 min",
"value" : 22
},
"end_location" : {
"lat" : 59.2394792,
"lng" : 15.1854676
},
"html_instructions" : "Sväng \u003cb\u003evänster\u003c/b\u003e för att fortsätta på \u003cb\u003eHalltorpsvägen\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestinationen kommer att vara på vänster sida\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "agqhJa~t{AZZFLDP"
},
"start_location" : {
"lat" : 59.23968980000001,
"lng" : 15.1857688
},
"travel_mode" : "WALKING"
}
],
"travel_mode" : "WALKING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "yyshJk|z{AdBR?FKjEEvB?vCHjLH|FHbE?p@ANJtEPlJLfD\\`CbAdFd@bCJbG^jSFvAV~@d@`ADR\\fABNFLHDJCh@ZF?\\`@DPAXEl@O~@OlAAP@FHF\\Bb@QRGf@El@N|@Tf@X^Br@TtAbAdAp@RTl@xAl@jCTl@Vb@PP\\LbAHx@Zn@E`BQ|AYdAO~@D\\F`@Pv@Fn@@jA_@l@[F\\HhAb@tJ@Zb@EDPH|@P`A`@n@BdHd@Mx@I\\C|@B~ACr@R^ZRZVr@Np@Fl@Br@@rAZZL^"
},
"summary" : "Karlsdalsallén och Sommarrovägen",
"warnings" : [
"Gångbeskrivningar är en betafunktion. Var försiktig – trottoarer och gångvägar kanske saknas i den här rutten."
],
"waypoint_order" : []
}
],
"status" : "OK"
}




How do I for example access the "duration" : "text" value in a flow block?

Henrik "The Developer" Lindqvist

unread,
Jan 8, 2018, 9:20:35 PM1/8/18
to Automate
json["routes"][0]["legs"][0]["duration"]
Reply all
Reply to author
Forward
0 new messages