• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[GUIDE][Difficulty: Advanced] Send an SMS with Address, Speed, and URL for a Map Pin

Search This thread

MishaalRahman

Editor in Chief
Nov 2, 2015
1,042
2,131
www.xda-developers.com
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

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

  1. 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.
  2. Create a Task and name it 'Get Location.'
MHgrSOq.jpg


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.

  1. 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.
  2. (If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.
  3. Location --> Get Location. Set the source as Any.
  4. 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
  5. 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","");
     }
  6. Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:
    Code:
    %add 
    Speed ~ %spd mph 
    URL: %url
wdN9BdL.jpg


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.
 

Attachments

  • Send_Location.prf.xml
    4.1 KB · Views: 2,622
Last edited:

Cryorus

Member
Sep 23, 2015
42
4
Hi,

Just bought tasker and setted this up, seems like the url query is not working, any tips?

Also, putting that url in chrome gives me the following:

Code:
{
"results" : [],
"status" : "ZERO_RESULTS"
}

Regards.
 
Last edited:

patrickpetersen

Senior Member
Jun 27, 2010
182
25
Esbjerg
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

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

  1. 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.
  2. Create a Task and name it 'Get Location.'
MHgrSOq.jpg


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.

  1. 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.
  2. (If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.
  3. Location --> Get Location. Set the source as Any.
  4. 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
  5. 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","");
     }
  6. Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:
    Code:
    %add 
    Speed ~ %spd mph 
    URL: %url
wdN9BdL.jpg


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.
The part where you used +"%22N" and +"%22W" wouldn't it only make it work in the northern part of America?
Tried it out, and by my location I should be in Denmark, but the URL leads me to be somewhere in the Atlantic Ocean.

If I delete the two parts or simply change the W to an E, it works... But isn't it possible to make Google determine if it should be N/S and W/E? I mean, it can be fixed with an If(), but isn't there a way to make the api do that? But that's a cool script! I've been looking for ages for a function that could do the speed without root - you helped me out, thanks!
 

MishaalRahman

Editor in Chief
Nov 2, 2015
1,042
2,131
www.xda-developers.com
Dropped pin is not accurate, its showing all blue area. Whats the problem?

Sometimes, the URL that gets sent in the SMS doesn't format properly (there's nothing you can do about that except maybe use a URL shortener service) so you'll have to make sure you copy/paste the ENTIRE URL that gets sent rather than just clicking on what it gives you.

Hi,

Just bought tasker and setted this up, seems like the url query is not working, any tips?

Also, putting that url in chrome gives me the following:

Code:
{
"results" : [],
"status" : "ZERO_RESULTS"
}

Regards.

Hi, it's perhaps failing because your phone failed to get a location lock, meaning %LOC is not being set. If %LOC is not set, then the URL query will not work as Google Maps is expecting GPS coordinates being passed to it. As for why it doesn't work when you open the URL in Chrome, same reason.

One thing you can do is add an Alert --> Flash command and Flash %LOC right after the "Get Location" action. If you don't see GPS coordinates pop up then it means Tasker timed out on getting a location on you.
 

MishaalRahman

Editor in Chief
Nov 2, 2015
1,042
2,131
www.xda-developers.com
The part where you used +"%22N" and +"%22W" wouldn't it only make it work in the northern part of America?
Tried it out, and by my location I should be in Denmark, but the URL leads me to be somewhere in the Atlantic Ocean.

If I delete the two parts or simply change the W to an E, it works... But isn't it possible to make Google determine if it should be N/S and W/E? I mean, it can be fixed with an If(), but isn't there a way to make the api do that? But that's a cool script! I've been looking for ages for a function that could do the speed without root - you helped me out, thanks!

You are correct. To make the Javascriptlet work globally, you would need to do the following (this is from the Redditor that came up with the Javascript):

This assumes you're using North latitude numbers and West longitude numbers (so North America). If you want to use it globally, this would be the way to do it:

In the javascriptlet, check the sign (+ or -) of lon before getting the absolute value, and assign a new variable string with either W or E based on the sign. Do the same thing with lat (after the lat=lat[0] line) and with N or S. Then near the bottom where it puts the degrees, minutes, and seconds together, use that string variable after the "%22". I haven't tested it but that should work.
 

Cryorus

Member
Sep 23, 2015
42
4
Sometimes, the URL that gets sent in the SMS doesn't format properly (there's nothing you can do about that except maybe use a URL shortener service) so you'll have to make sure you copy/paste the ENTIRE URL that gets sent rather than just clicking on what it gives you.



Hi, it's perhaps failing because your phone failed to get a location lock, meaning %LOC is not being set. If %LOC is not set, then the URL query will not work as Google Maps is expecting GPS coordinates being passed to it. As for why it doesn't work when you open the URL in Chrome, same reason.

One thing you can do is add an Alert --> Flash command and Flash %LOC right after the "Get Location" action. If you don't see GPS coordinates pop up then it means Tasker timed out on getting a location on you.

Thanks for the tip, it seems that step 3. Get Location takes a while (around a minute or more) to complete, after that, Flashing %LOC doesn't return anything.

Edit: Working now, I turned options for GPS to use Wifi and Bluethooth and it worked, but the link isn't sent completly, the hyperlink breaks at the first comma. Example: www.url.com/22w22s1234,etc.

Edit 2: Just read that there is nothing to do about it... gona find a way around.

Edit 3: Found a way around using the bitly API, the problem now is even if I change the location N to S (I'm in South America) it doesn't pin anything. (It doesnt even with N)
 
Last edited:

patrickpetersen

Senior Member
Jun 27, 2010
182
25
Esbjerg
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

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

  1. 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.
  2. Create a Task and name it 'Get Location.'
MHgrSOq.jpg


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.

  1. 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.
  2. (If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.
  3. Location --> Get Location. Set the source as Any.
  4. 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
  5. 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","");
     }
  6. Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:
    Code:
    %add 
    Speed ~ %spd mph 
    URL: %url
wdN9BdL.jpg


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.

Can someone edit the script and provide me for global? I am in Pakistan and its not showing accurate drop pin.

Try to follow the instructions from the redditor or manually switch the 22N to 22S and 22W to 22E :)
 
  • Like
Reactions: MishaalRahman

Ben Abel

Member
Nov 4, 2012
32
1
Cleveland, TN
Thanks for the tip, it seems that step 3. Get Location takes a while (around a minute or more) to complete, after that, Flashing %LOC doesn't return anything.

Edit: Working now, I turned options for GPS to use Wifi and Bluethooth and it worked, but the link isn't sent completly, the hyperlink breaks at the first comma. Example: www.url.com/22w22s1234,etc.

Edit 2: Just read that there is nothing to do about it... gona find a way around.

Edit 3: Found a way around using the bitly API, the problem now is even if I change the location N to S (I'm in South America) it doesn't pin anything. (It doesnt even with N)

I'm having this problem as well, the "Get Location" times out no matter how high I set the time out value to be. I've Turned on WiFi and Bluetooth scannaing to no avail. Whenever the task runs, I see the GPS icon show up in my status bar. And Google Maps has no problem getting my location quickly and accurately. I'm not sure what's going on :confused:
 

Cryorus

Member
Sep 23, 2015
42
4
I'm having this problem as well, the "Get Location" times out no matter how high I set the time out value to be. I've Turned on WiFi and Bluetooth scannaing to no avail. Whenever the task runs, I see the GPS icon show up in my status bar. And Google Maps has no problem getting my location quickly and accurately. I'm not sure what's going on :confused:

Did you test it outside? It takes a while to get my location here at my work, but outside it is super fast.
 

Rythyrix

Member
Aug 1, 2015
10
2
Big Brother now works for me. Thanks, MishaalRahman.

One thing to point out for paranoid/right peoplle, it is possible to make an email-to-SMS gateway trigger it, although it does require setting up a new Context.
For those who do not know, a SMS gateway is when you send an email to a carrier's portal, and they pass the message along as an SMS. It also works backwards, sending an SMS back will send the reply to the sending email address. Wikipedia has a list of U.S. ones. For those outside the U.S., some research will be required, so go practice your Google-fu.

One thing to check for is the message may be wrapped in transit with things like the sender's name, subject line, etc. Test it out thoroughly, as the Context's contents must match the SMS exactly in order to trigger the Task. I recommend sending the message and simply copy/pasting what it spits out as the new Context's contents.

Last caveat, check to make sure that the message actually comes through the email reply, AT&T's SMS-to-email parser breaks on the degree symbol (Unicode B0 ALT+0176 °), so some editing may be required on the receiving end prior to presenting the URL to Gmaps. Once again, test thoroughly.
 

Motofarer

New member
May 21, 2016
1
0
I love the whole idea. It's great! Can you please write the Java scriptlet for me that works anywhere in the world? Requesting because I do not know coding at all.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 15
    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

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

    1. 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.
    2. Create a Task and name it 'Get Location.'
    MHgrSOq.jpg


    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.

    1. 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.
    2. (If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.
    3. Location --> Get Location. Set the source as Any.
    4. 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
    5. 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","");
       }
    6. Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:
      Code:
      %add 
      Speed ~ %spd mph 
      URL: %url
    wdN9BdL.jpg


    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.
    1
    Maybe publish the script that can be downloaded and inserted from tasker. Thanks.

    I've attached the script in the post. Enjoy!
    1
    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

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

    1. 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.
    2. Create a Task and name it 'Get Location.'
    MHgrSOq.jpg


    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.

    1. 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.
    2. (If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.
    3. Location --> Get Location. Set the source as Any.
    4. 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
    5. 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","");
       }
    6. Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:
      Code:
      %add 
      Speed ~ %spd mph 
      URL: %url
    wdN9BdL.jpg


    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.

    Can someone edit the script and provide me for global? I am in Pakistan and its not showing accurate drop pin.

    Try to follow the instructions from the redditor or manually switch the 22N to 22S and 22W to 22E :)