Need to start from the inner one first. {loc} is the variable which contain the location coordinate (you use your own global variable in this case). It is an object type, which can't be access like usual string, unless you show in one of the formatting.
"{loc,locationformat,decimal}" is one of the formatting you can use for location. It is almost like excel cell formatting, where you can determine how many decimal point (example 1.23), or how the date are shown in the final form (example 20180619 or 19 June 2018). At the script action, press the icon question mark (?), and search for locationformat, at 2nd occurrence you will find the documentation on how to format the location. "decimal" is one of the format, which will show the location as decimal numbers, in lat,long format, string type.
What you want to do here, actually can be done using "{loc,locationformat}", it will query the geocode using google map api. However it is very limited, as I've tested, it only accept 3 requests everyday (already used up during testing the flow
). So I don't use it, I also use the openMap API.
We then wrap this string into the split() function, as the first parameter. Since it has one comma, it will be splitted to 2 parts, and the result is a list type variable {str}, which contains 2 elements. We then accessed each part using the list index, 0 is the lat and 1 is the lon.
After you substitute this in the url, send the http request and get the response in JSON; we need to parse this JSON to get the data we need. Since Automagic is very JSON friendly, we can simply convert the JSON to a map/list object by using fromJSON() and store it into a new variable, example {js}.
This will convert the response into usable map/list object. It has nested map/list element, so we need to dig deeper to get the city. If you use a condition debug dialog after this, you can try to change value at {js}, you can dig down each value to the nested map/list. city is located under the address, so we need to access it by
Code: Select all
js = fromJSON(response);
city = js["address"]["city"];
You will get city = Birmingham.
==================================
The full documentation is already in each action help page. But the complete documentation of all elements can be found in the main website (not forum). You can find the link to each of the documentation, examples and quick tutorial in my index, at the General section. Or you can find more example usages (including this JSON format) at the HTTP request, JSON, .... section and another one at Scripting section. There is also a step by step using Debug Dialog to help and troubleshooting scripting problem at the troubleshooting section. By using the debug diaog, you can dig down into js and access the other value you might need.