Task that retrieves the 'zipcode' from location (%LOC) task

1,283 views
Skip to first unread message

DaWeav

unread,
Aug 10, 2010, 1:50:13 AM8/10/10
to Tasker
I finally think figured out a way to get my location's ZIPCODE using
the %LOC variable via Google's pseudo reverse-geocoding, and I would
like to know if this Task works for anyone else but me. It's useful
for me when I'm getting things like Sunrise & Sunset Times or Weather
stuff from RSS or XML feeds that use my zipcode instead of lat & long.

Task GET-ZIPCODE List

1) HTTP-GET
Server-Port: maps.google.com/maps/api/geocode/json?latlng=
%LOC&sensor=false
Mime Type: text/xml

Note: All of the quotes, colons, commas, spaces, and underscores
should be included in these splits.

2) Variable Split %HTTPD splitters
"county", "political"
(has four quotes, one comma, and one space after the comma)

3) Variable Split %HTTPD2 splitter
"short_name"
(has two quotes, and one underscore)

4) Variable Split %HTTPD21 splitter
"long_name": "
(has three quotes, one underscore, one colon and one space after the
colon)

5) Variable Split %HTTPD212 splitter
",
(has one quote, and one comma)

6) Variable Set name %ZIPCODE to %HTTPD2121

7) Alert Popup text %ZIPCODE

Chris

unread,
Aug 10, 2010, 4:56:25 AM8/10/10
to Tasker
Good one, works

Dave

unread,
Aug 10, 2010, 5:58:47 PM8/10/10
to Tasker
It worked, except it should be "country" and not "county" (with an
'r') in step 2. I like how you specified the special characters.

On Aug 10, 12:50 am, DaWeav <wwwjunkem...@gmail.com> wrote:
> I finally think figured out a way to get my location's ZIPCODE using
> the %LOC variable via Google's pseudo reverse-geocoding, and I would
> like to know if this Task works for anyone else but me.  It's useful
> for me when I'm getting things like Sunrise & Sunset Times or Weather
> stuff from RSS or XML feeds that use my zipcode instead of lat & long.
>
*snip*

>
> 2)  Variable Split %HTTPD splitters
>       "county", "political"
> (has four quotes, one comma, and one space after the comma)

*snip*

DaWeav

unread,
Aug 10, 2010, 8:49:48 PM8/10/10
to Tasker
Thanks. I even triple checked it to make sure I didn't typo anything,
but I still did it anyway.

I'm glad to know it works on other Androids besides mine.

Benny - Motorola Droid 2.1

unread,
Aug 10, 2010, 8:55:47 PM8/10/10
to Tasker
Worked for me :)

On Aug 10, 2:58 pm, Dave <hathaway.d...@gmail.com> wrote:

UFO64

unread,
Aug 21, 2010, 2:40:45 AM8/21/10
to Tasker
I am adapting this to work with the town name, as apposed to the ZIP
code. It seems that the XML is different when google cannot find an
address near you. The result is that the code can error rather easily
if you arn't near a street address.

Are there any 'geocoding' URLs that have more predictable output, or
does anyone know a way to get google to just output the specific
variables in the XML?

konradwalsh

unread,
Aug 21, 2010, 8:34:25 AM8/21/10
to Tasker
try geonames

UFO64

unread,
Aug 21, 2010, 3:00:48 PM8/21/10
to Tasker
Ahh, that service worked perfectly.

I ended up with the following string...

http://ws.geonames.org/findNearbyPlaceNameJSON?lat=%LOC1&lng=%LOC2&style=short

Obviously you need to split %LOC by "," to get the lat and lng split
up, but other then that it makes a fairly easy string to chop up!

konradwalsh

unread,
Aug 22, 2010, 10:14:03 AM8/22/10
to Tasker
would you mind sharing your profile details.. would love to see it
working

On Aug 21, 8:00 pm, UFO64 <jmurray...@gmail.com> wrote:
> Ahh, that service worked perfectly.
>
> I ended up with the following string...
>
> http://ws.geonames.org/findNearbyPlaceNameJSON?lat=%LOC1&lng=%LOC2&st...

david morin

unread,
Jan 7, 2012, 4:49:14 PM1/7/12
to tas...@googlegroups.com
all i get in the popup is %HTTPD2121

david morin

unread,
Jan 7, 2012, 5:05:06 PM1/7/12
to tas...@googlegroups.com
Here is a screen of my setup
CAP201201071702.png

lostmedic

unread,
Feb 1, 2012, 10:41:10 PM2/1/12
to Tasker
was anyone able to fix this? that is all I want is the zipcode.

dp106

unread,
Feb 2, 2012, 4:26:46 AM2/2/12
to Tasker
I've been trying to do this and get similar results, my theory is that
the results are more than 4k and so %HTTPD isn't populated. The only
way around this I've found so far is to output the results to a file.

I've then been reading the file in one line at a time but tasker
doesn't seem very efficient at doing this so having more issues with
that :-S

Adi

unread,
Jul 26, 2012, 1:25:12 PM7/26/12
to tas...@googlegroups.com
trying this myself, but getting no popup. Can't verify that zip-code is populating. Tips?
(HTC Glacier, Android 2.3.4)

Cory Carter

unread,
Nov 6, 2012, 5:56:21 PM11/6/12
to tas...@googlegroups.com
Not sure why just yet but I will be playing with this more but the HTTPD2121 doesnt have info which means ZIPCODE doesnt either. But I made it put an output file and it seems like its locking on my location and finding me just fine.


On Tuesday, August 10, 2010 1:50:13 AM UTC-4, DaWeav wrote:

Andrew Hall

unread,
Nov 7, 2012, 5:11:26 AM11/7/12
to tas...@googlegroups.com
Hmm I get an unknown host error. does it matter that I am in the uk?

John Spillett

unread,
Nov 8, 2012, 6:53:49 AM11/8/12
to tas...@googlegroups.com
This is almost  the Task list that I have been using for some time.

GetPlaceName (18)
      A1: Variable Clear [ Name:%LOCNAME Pattern Matching:Off ]
      A2: Variable Clear [ Name:%PCODE Pattern Matching:Off ]
      A3: Flash [ Text:PLEASE WAIT Long:On ]
      A4: HTTP Get [ Server:Port:maps.google.com/maps/api/geocode/json?latlng=%LOCN&sensor=false Path: Attributes: Cookies: Timeout:10 Mime Type:text/xml Output File:pcode ]
      A5: Variable Set [ Name:%PLACE To:%HTTPD Do Maths:Off Append:Off ]
      A6: Variable Split [ Name:%HTTPD Splitter:"types" : [ "country", "political" ] Delete Base:On ]
      A7: Variable Split [ Name:%HTTPD2 Splitter:{ Delete Base:On ]
      A8: Variable Split [ Name:%HTTPD22 Splitter:: " Delete Base:Off ]
      A9: Variable Set [ Name:%POST To:%HTTPD222 Do Maths:Off Append:Off ]
      A10: Variable Clear [ Name:%HTTP* Pattern Matching:On ]
      A11: Variable Split [ Name:%POST Splitter:" Delete Base:Off ]
      A12: Variable Set [ Name:%PCODE To:
%POST1 Do Maths:Off Append:Off ]
      A13: Variable Split [ Name:%PLACE Splitter:"route" Delete Base:Off ]
      A14: Variable Split [ Name:%PLACE2 Splitter:: " Delete Base:Off ]
      A15: Variable Split [ Name:%PLACE22 Splitter:" Delete Base:Off ]
      A16: Variable Set [ Name:%LOCNAME To:%PLACE221 Do Maths:Off Append:Off ]
      A17: Variable Clear [ Name:%PLACE* Pattern Matching:On ]
      A18: Show Scene [ Name:HTTP Display As:Dialog Horizontal Position:100 Vertical Position:100 Show Exit Button:On Continue Task Immediately:On ]
 %PCODE is Postcode

Scene shows %PCODE and %LOCNAME

Dave Fisher

unread,
Nov 8, 2012, 7:14:13 AM11/8/12
to tas...@googlegroups.com
This is what I use for obtaining the locality, you should be able to just change

var localityName = extractData(parsedData.results[0].address_components, 'locality');

to

var localityName = extractData(parsedData.results[0].address_components, 'postal_code');

to get the post code for the current area.

Note that I use %LATLON which is set from a %LOC, %LOCN or a specific location depending on a million other criteria :)



getLocation (38)
A1: HTTP Get [ Server:Port:maps.googleapis.com Path:/maps/api/geocode/json Attributes:latlng=%LATLON
sensor=false Cookies: Timeout:20 Mime Type:text/plain Output File: Continue Task After Error:On ] 
A2: If [ %HTTPR ~ 200 ]
A3: JavaScriptlet [ Code:var parsedData = JSON.parse(global('HTTPD'));

var localityName = extractData(parsedData.results[0].address_components, 'locality');

setGlobal('CURRLOCALITY', localityName.toUpperCase());


function extractData(components, type) {
    for (var i=0; i<components.length; i++)
        for (var j=0; j<components[i].types.length; j++)
            if (components[i].types[j]==type) return components[i].long_name;
    return "";
} Libraries: Auto Exit:On Timeout (Seconds):45 ] 
A4: Else 
A5: Variable Set [ Name:%CURRLOCALITY To:N/A Do Maths:Off Append:Off ] 
A6: End If 

ScottS

unread,
Feb 14, 2013, 11:19:47 AM2/14/13
to tas...@googlegroups.com, mob...@the-darkside.co.uk
I would like to integrate auto locale into my existing weather task. I would assume I add the locality script as A1, but how do I call it properly, based on my existing Task? Do I replace the location (/TX/Dallas) in the HTTP Get with a variable? Maybe I need to 'Get' my initial data from a different server/source?

Weather forecast (27)
A1: HTTP Get [ Server:Port:ical.wunderground.com/auto/ical/TX/Dallas.ics Path: Attributes: Cookies: Timeout:10 Mime Type:text/xml Output File: ]
A2: Variable Set [ Name:%result To:%HTTPD Do Maths:Off Append:On ]
A3: Variable Split [ Name:%result Splitter:DESCRIPTION: Delete Base:On ]
A4: Variable Split [ Name:%result2 Splitter:\n Delete Base:Off ]
A5: Say [ Text:Here is the weather report for %result21 Engine:Voice:eng-us Stream:3 Pitch:5 Speed:5 Continue Task Immediately:Off ]

John Spillett

unread,
Feb 15, 2013, 12:50:49 PM2/15/13
to tas...@googlegroups.com
This one extracts opcode (postcode ) GetPlaceName (18)
A1: Show Scene [ Name:Wait Display As:Dialog Horizontal Position:100 Vertical Position:100 Show Exit Button:On Continue Task Immediately:On ]
A2: Variable Clear [ Name:%LOCNAME Pattern Matching:Off ]
A3: Variable Clear [ Name:%PCODE Pattern Matching:Off ]
A4: HTTP Get [ Server:Port:maps.google.com/maps/api/geocode/json?latlng=%LOCN&sensor=false Path: Attributes: Cookies: Timeout:10 Mime Type:text/xml Output File:pcode ]
A5: Variable Set [ Name:%PLACE To:%HTTPD Do Maths:Off Append:Off ]
A6: Variable Split [ Name:%HTTPD Splitter:"types" : [ "country", "political" ] Delete Base:On ]
A7: Variable Split [ Name:%HTTPD2 Splitter:{ Delete Base:On ]
A8: Variable Split [ Name:%HTTPD22 Splitter:: " Delete Base:Off ]
A9: Variable Set [ Name:%POST To:%HTTPD222 Do Maths:Off Append:Off ]
A10: Variable Clear [ Name:%HTTPD* Pattern Matching:On ]
A11: Variable Split [ Name:%POST Splitter:" Delete Base:Off ]
A12: Variable Set [ Name:%PCODE To:
%POST1 Do Maths:Off Append:Off ]
A13: Variable Split [ Name:%PLACE Splitter:"route" Delete Base:Off ]
A14: Variable Split [ Name:%PLACE2 Splitter:: " Delete Base:Off ]
A15: Variable Split [ Name:%PLACE22 Splitter:" Delete Base:Off ]
A16: Variable Set [ Name:%LOCNAME To:%PLACE221 Do Maths:Off Append:Off ]
A17: Variable Clear [ Name:%PLACE* Pattern Matching:On ]
A18: Hide Scene [ Name:Wait Continue Task After Error:On ]
A19: Show Scene [ Name:HTTP Display As:Dialog Horizontal Position:100 Vertical Position:100 Show Exit Button:On Continue Task Immediately:On ]
Message has been deleted

ScottS

unread,
Feb 22, 2013, 11:47:10 AM2/22/13
to tas...@googlegroups.com
How do I get the above to 'Say'. What variable(s) should be stated in the 'Text' section, and what Actions may be removed?

Say [ Text:Here is the weather report for %____________

ScottS

unread,
Mar 1, 2013, 4:12:55 PM3/1/13
to tas...@googlegroups.com
ping

John Spillett

unread,
Mar 2, 2013, 1:28:22 PM3/2/13
to tas...@googlegroups.com
%PCODE contains the UK post code.
 
Hope this helps.

Nicholas Pongallo

unread,
Mar 3, 2013, 7:23:08 PM3/3/13
to tas...@googlegroups.com
So for all those still having trouble, this is the fix that worked for me.

On the variable split %HTTPD21 my splitter is this:

] }, { "long_name" : "

The way I found that is in eye variables under %HTTPD21 it was not just "long_name" : " it was what I listed above. So i just copied what I saw in the variable before the Zipcode and it worked.

Hope this will help someone!

ScottS

unread,
Mar 4, 2013, 9:17:45 AM3/4/13
to tas...@googlegroups.com
I found and tweaked the following Profile from the wiki:  Gets and Speaks Weather for Current Location in Morning

Scott

unread,
Apr 16, 2013, 12:37:34 PM4/16/13
to tas...@googlegroups.com

Here is what I use.

 

From: tas...@googlegroups.com [mailto:tas...@googlegroups.com] On Behalf Of Christopher Lewis
Sent: Monday, April 15, 2013 9:51 PM
To: tas...@googlegroups.com
Subject: Re: Task that retrieves the 'zipcode' from location (%LOC) task

 

Scott, I'd like to mod your profile to send the weather to my Pebble watch.  Any chance you can share you updated profile that pulls currently location? 




On Monday, March 4, 2013 7:17:45 AM UTC-7, ScottS wrote:

I found and tweaked the following Profile from the wiki:  Gets and Speaks Weather for Current Location in Morning

 

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/LklOAoVfm-s/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

sayweather.zip

Christopher Lewis

unread,
Apr 17, 2013, 1:31:20 AM4/17/13
to tas...@googlegroups.com
Thanks again Scott.  I got it to work and send the information to my Pebble.  One thing I'd like to add is the current temperature.  I can't seem to find the XML link at wunderground to get that info like you have the forecast and location info.  I've tried several things in place of the ForecastXML portion of the link without success.  Is there a list somewhere that shows what links I can use?

Scott

unread,
Apr 17, 2013, 10:00:54 AM4/17/13
to tas...@googlegroups.com

Here’s what I use for current weather.

 

From: tas...@googlegroups.com [mailto:tas...@googlegroups.com] On Behalf Of Christopher Lewis
Sent: Wednesday, April 17, 2013 12:31 AM
To: tas...@googlegroups.com
Subject: Re: Task that retrieves the 'zipcode' from location (%LOC) task

 

Thanks again Scott.  I got it to work and send the information to my Pebble.  One thing I'd like to add is the current temperature.  I can't seem to find the XML link at wunderground to get that info like you have the forecast and location info.  I've tried several things in place of the ForecastXML portion of the link without success.  Is there a list somewhere that shows what links I can use?

--

Current_Weather.tsk.xml

Saad Thahim

unread,
Mar 17, 2015, 1:47:14 AM3/17/15
to tas...@googlegroups.com
Can you please share it as xml?
Message has been deleted

Scott Windham

unread,
Mar 18, 2015, 12:57:22 PM3/18/15
to tas...@googlegroups.com


Hello,
  I have played around with this. I came up with my own version.
Now works here in the U.S.  ( Florida ), Other places not sure
GetAddress
123 Street Name
City, State,  zipcode , USA
long and lat

ZipcodeOnly
just that  zip code only

GetAddress2.tsk.xml
ZipcodeOnly.tsk.xml
Reply all
Reply to author
Forward
0 new messages