Hi
So I'm trying to setup a weather report, and have it say what suburb (or city) I am in.
Weather underground gives me some wack settings, while the temperature is correct the location is just wrong.
So I tried using init.variable.location and it gives me a full address of where I'm at. (IE: 22 fake st, faketown western Australia 6000). No matter which setting I try.
So am I able to make it just give me the information of the city (faketown in example) so I can setup speech to say that...
Thanks in advance
Location information
Moderator: Martin
Re: Location information
I don't know the return string from the address. But if it always give you number, street name, city, region in the same format, you can probably use regex to parse it.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
-
- Posts: 4
- Joined: 11 Feb 2018 06:35
Re: Location information
Can you give me some hint at where to start for that? I'm learning as I go and dont have much experience with this. 
Thanks

Thanks
Re: Location information
Thanks to your question. I am just about the time to find the method to query the full location name (if possible). Yesterday I tested it out for a while only, as I am still focusing on my speech flow (till now). Today I tested it again, and it works using google map API. However there is limit to number of query we can make per day.
Automagic itself already has built-in method to query location name, which you have used. (It seems to use the same google map API, but using developer API key). After getting the location coordinate (in latlong format) from Init Variable Location, simply show it in locationformat.
There is other format too, such as multiline; but I tested it out and it doesn't show the name in administrative order.
That's why I use google map API for geocode. I found it from tasker thread, but there is documentation too from google. What you need is only the latlong coordinate (location) from the init location, and pass it thru the API using HTTP request.
Action : HTTP Request
URL : https://maps.googleapis.com/maps/api/ge ... nsor=false
All other fields leave default
The result is response will contains the JSON response from the API. We can then parse the JSON to get the info we want. Unlike tasker, where the JSON parsing is a nightmare; Using Automagic, it is easy as piece of cake, as it is very JSON-friendly. Simply convert it to object by using fromJSON() and then browse to the value you want and you only need single line of script per information you need. It is a combination of map and list. The result shows you a list of address query from street name, area level 4, 3, 2, 1 up to country. Most of the information are available in the street name though, since it covers all. For example, you want the city/town, it is at area level 2, at index 4 of the street name. While street name is at index 1.
Action Script
Don't be afraid for such a long nested script, it is actually very easy to understand. You can find the level which you need, by attaching condition debug dialog after the script. Find the js and change value, you will see two map. Dig down at results, change value, you see a lot of list. Change value at element 0, there is address_components, and so on till you find the value you need. I find the town and street (or any information from the json) using the same method. I don't memorize it at all, i still use the debug dialog to help me create this nested map/list assignment.
However, since there is a limited time of usage per day, you should be careful not to query too often. You might want to save the js to a glovar, so you can analyze it later at the glovar menu.
@Martin : I wish there is a format or function or Action, where we can query the location and get the result just like in the response above. Or maybe just directly return the list/map of the street, area level 4 up till country.
Automagic itself already has built-in method to query location name, which you have used. (It seems to use the same google map API, but using developer API key). After getting the location coordinate (in latlong format) from Init Variable Location, simply show it in locationformat.
Code: Select all
fulladdress = "{location,locationformat}";
That's why I use google map API for geocode. I found it from tasker thread, but there is documentation too from google. What you need is only the latlong coordinate (location) from the init location, and pass it thru the API using HTTP request.
Action : HTTP Request
URL : https://maps.googleapis.com/maps/api/ge ... nsor=false
All other fields leave default
The result is response will contains the JSON response from the API. We can then parse the JSON to get the info we want. Unlike tasker, where the JSON parsing is a nightmare; Using Automagic, it is easy as piece of cake, as it is very JSON-friendly. Simply convert it to object by using fromJSON() and then browse to the value you want and you only need single line of script per information you need. It is a combination of map and list. The result shows you a list of address query from street name, area level 4, 3, 2, 1 up to country. Most of the information are available in the street name though, since it covers all. For example, you want the city/town, it is at area level 2, at index 4 of the street name. While street name is at index 1.
Action Script
Code: Select all
js = fromJSON(response);
town = js["results"][0]["address_components"][4]["long_name"];
street = js["results"][0]["address_components"][1]["long_name"];
However, since there is a limited time of usage per day, you should be careful not to query too often. You might want to save the js to a glovar, so you can analyze it later at the glovar menu.
Code: Select all
global_js_map = js;
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
-
- Posts: 4
- Joined: 11 Feb 2018 06:35
Re: Location information
Thanks mate, I'll check it out on the weekend.
-
- Posts: 4
- Joined: 11 Feb 2018 06:35
Re: Location information
I struggled like anything to understand how you went about doing it... And I figured it out...
I wrote the location to a text file, created a variable text file. Then ran this script.
//split the text into a list of lines
line=split(locate,'\\ ');
number = getElement(line, 0);
street = getElement(line, 1);
street2 = getElement(line, 2);
suburb = getElement(line, 3);
postcode = getElement(line, 4);
Then after the speech has been said, delete the text file.
Winner.
I wrote the location to a text file, created a variable text file. Then ran this script.
//split the text into a list of lines
line=split(locate,'\\ ');
number = getElement(line, 0);
street = getElement(line, 1);
street2 = getElement(line, 2);
suburb = getElement(line, 3);
postcode = getElement(line, 4);
Then after the speech has been said, delete the text file.
Winner.
Re: Location information
You don't need to save to text file, you can directly split it there. This won't work properly if your current location name doesn't have full address. (Example no street number). But it should work properly in most cases.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.