2016-03-07

Your phone is lost, or you've got a relative who you're okay with sharing your location to. If you're driving, it's hard to give them an exact location, but thanks to the power of Tasker and a Javascriptlet, you can do that and more. With this task, you'll be able to automatically send an SMS with the current Address, current Speed that the phone is traveling, and a URL that drops a pin on the phone's location in Google Maps. Very helpful for easily finding a location! I would like to thank Redditor /u/popillol for figuring out the proper Javascriptlet to parse the Google Maps Geocoding API results.

Prerequisites

Secure Settings plugin if you are rooted and want to be able to automatically toggle location mode

Create a new Profile and select the Event context. Go to Phone and select Received Text. For the Type, leave it at Any and the Sender field blank. However for the Content field, choose a trigger phrase that you will share with your trusted relatives. This trigger phrase should be unique enough that there is no way it will trigger based off of any random text message.

Create a Task and name it 'Get Location.'



Now, for the task itself. Be warned that this involves some Javascript, so be sure you copy/paste the functions in properly otherwise it might not work.

Variables --> Variable Set. Set Name to %from and To to %SMSRF. This gets the phone number that the text was sent from and puts it into a variable called %from.

(If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.

Location --> Get Location. Set the source as Any.

Net --> HTTP Get. Under Server:Port, put in the following URL to access the Google Maps Geocoding API:

Code:

maps.google.com/maps/api/geocode/json?latlng=%LOC&sensor=false

Set Mime Type as text/xml

Code --> Javascriptlet. For the code, add the following:

Code:

var locj = JSON.parse(global("%HTTPD"));

var spd = Number(global("%LOCSPD"))*2.23693629;

var lat = global("%LOC").split(",");

var lon = Math.abs(lat[1]);

lat = lat[0];

var latd = Math.floor(lat);

var latm = ( lat - latd )*60;

var lats = ( latm - Math.floor(latm) )*60;

latm = Math.floor(latm);

var lond = Math.floor(lon);

var lonm = ( lon - lond )*60;

var lons = ( lonm - Math.floor(lonm) )*60;

lonm = Math.floor(lonm);

lat = latd+"\°"+latm+"\'"+lats.toFixed(1)+"%22N";

lon = lond+"\°"+lonm+"\'"+lons.toFixed(1)+"%22W";

var url = "https://www.google.com/maps/place/"+lat+"+"+lon+"/@"+global("%LOC")+",14z";

if ( locj.results.length > 0 )

{

var short = locj.results[0].address_components[0].short_name;

if ( short.search(/[^\d-]/) == -1 )

short = "";

else

short = "("+short+") ";

var add = locj.results[0].formatted_address;

add = short+add.replace(", USA","");

}

Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:

Code:

%add

Speed ~ %spd mph

URL: %url



That's it! As mentioned in the Reddit thread for this, you can use AutoInput to automate turning on/off location services if you aren't rooted, but it's a bit of a messy implementation so I recommend just leaving location services on.

Show more