%LOC +- Radius or Why Location context didn't get %VAR

834 views
Skip to first unread message

V Oz

unread,
Jan 11, 2012, 4:52:19 AM1/11/12
to tas...@googlegroups.com
can't find in group.
How to test is %LOC near Point(Lat,Long) +- Radius?
What the math operations are used to fire Location context?
all this can be solved when Location context can get %VAR (as %LOC format) for a Point coordinates.
Unfortunately, this is not in TODO list.

V Oz

unread,
Jan 11, 2012, 5:01:57 AM1/11/12
to tas...@googlegroups.com
hmmm 
100 m / 6378160 m = 0.000016 deg
Point Long - 0.000016 < %LOC < Point Long + 0.000016

Ok. It's the time to split variables view between projects. though they are remain global.

Pent

unread,
Jan 11, 2012, 6:14:04 AM1/11/12
to Tasker
> Unfortunately, this is not in TODO list.

Distance between two fixes is on the list, which is the same thing.

Pent

BossMan

unread,
Jan 11, 2012, 6:51:38 AM1/11/12
to tas...@googlegroups.com
If you do not need huge accuracy (it calculates travel distance, not the straight-line distance), for now you could try using google services for this:  http://code.google.com/apis/maps/documentation/distancematrix/



BR,
A.

BossMan

unread,
Jan 11, 2012, 6:55:36 AM1/11/12
to tas...@googlegroups.com

V Oz

unread,
Jan 11, 2012, 8:02:30 AM1/11/12
to tas...@googlegroups.com
Thanks a lot.
I think in my case couple of sums and subtracts and comparisons with a constant are much faster then powers and sqrt 

the aim was to set location for notification  via Scene->Map element and monitor it with Variable %LOC set event context.

Comparison algorithm is implemented yet in Location context as far as it works.
aaahh ... i got why we can't put variable to location context - in debug log I saw how Tasker makes prepares monitors ... for now it can't be dynamic.. 
Ok. my aim is have not high precision in time and loc accuracy.

Rick Nyman

unread,
Jan 15, 2012, 9:20:07 AM1/15/12
to Tasker
Here's a task that I use to calculate approximate distance and
direction between 2 locations. It takes two inputs in the form of
%LOC and returns distance in miles (rounded to tenths), and the
direction (N, NE, E, SE, S, SW, S, NW) from the first to the second.
Every degree of latitude is approximately 69 miles and every degree of
longitude is approximately 69 miles times the cosine of the latitude.

In practice, this seems accurate enough. If you only need distance,
you can stop after A3. You'll also see that I'm using 690 tenths of a
mile per degree, then dividing the final answer by 10 after rounding
it to get the precision I want.

I reuse the %compass variable, sorry if that's confusing.

Rick


Task: Drive:Vector (51)
A1: Variable Split [ Name:%par1 Splitter:, Delete Base:Off ]
A2: Variable Split [ Name:%par2 Splitter:, Delete Base:Off ]
A3: Variable Set [ Name:%distance To:round(sqrt(((%par11-
%par21)*690)^2+((%par12-%par22)*690*cos((%par11+%par21)/2))^2))/10 Do
Maths:On Append:Off ]
A4: If [ %distance > 0 ]
A5: Variable Set [ Name:%heading To:todeg(atan((%par22-
%par12)*cos((%par11+%par21)/2)/(%par21-%par11))) Do Maths:On
Append:Off ]
A6: Variable Add [ Name:%heading Value:180 Wrap Around:0 ] If
[ %heading < 0 ]
A7: Variable Add [ Name:%heading Value:180 Wrap Around:0 ] If
[ %par22-%par12 < 0 ]
A8: Variable Set [ Name:%index To:round(%heading/45) Do Maths:On
Append:Off ]
A9: Variable Set [ Name:%index To:8 Do Maths:Off Append:Off ] If
[ %index = 0 ]
A10: Else
A11: Variable Set [ Name:%index To:9 Do Maths:Off Append:Off ]
A12: End If
A13: Variable Set [ Name:%compass To:NE,E,SE,S,SW,W,NW,N,X Do
Maths:Off Append:Off ]
A14: Variable Split [ Name:%compass Splitter:, Delete Base:Off ]
A15: Variable Set [ Name:%compass To:%compass(%index) Do Maths:Off
Append:Off ]
A16: Return [ Value:%distance,%compass Stop:Off ]

Vladimir Oz

unread,
Aug 19, 2012, 6:22:38 AM8/19/12
to tas...@googlegroups.com
Here I'm again.
I see the "evaluate function (e.g. distance between two fixes)" right near the top of TODO. :)

Hope, it's will be realized soon. I'll test it as soon as it'll be there. ;)

среда, 11 января 2012 г., 15:14:04 UTC+4 пользователь Pent написал:
Message has been deleted

BaKaMu

unread,
Aug 19, 2012, 1:52:05 PM8/19/12
to tas...@googlegroups.com
Hi Vladimir,

> Hope, it's will be realized soon.

This can all be done already using JavaScript:

Copy
the script into a JavaScriptlet and run it!
(Test function is already included)

bakamu


Edit: (Dot instead of a comma (in number)

var tsec = 1003,252; //time in seconds for speed calculation
should be:
var tsec = 1003.252; //time in seconds for speed calculation


//=====================================

var result = ZGeoTestFunc();
alert(result);
exit();

//------------------------------------
//ZGeoTestFunc()
//------------------------------------
function ZGeoTestFunc ()
{
var retvar = '';
var isandroid = (global('%SDK') != '0');

//test points
var p1 = '40.748785, -73.984902'; //Empire State Building
var p2 = '40.742747, -73.972632'; //123 degree and 1234 m away
var tsec = 1003.252; //time in seconds for speed calculation

retvar += '----------' + '\n';
retvar += 'ZGeoDistance: ' + ZGeoDistance(p1, p2) + '\n'; //1234
retvar += 'ZGeoBearing: ' + ZGeoBearing(p1, p2, 0) + '\n'; //123.00103598235853
retvar += '----------' + '\n';
retvar += 'ZGeoSpeed: ' + ZGeoSpeed(p1, p2, tsec, 2) + '\n'; //1,23
retvar += 'ZGeoCompassDir: ' + ZGeoCompassDir(ZGeoBearing(p1, p2, 0)) + '\n'; //ESE 
retvar += '----------' + '\n';

return retvar;
}
//\ZGeoTestFunc ------------------------------------

//------------------------------------
//ZGeoDistance (pointa, pointb, dp)
//Returns the distance between point a and point b in m
//(using Haversine formula)
//Params: {string} pointa,pointb: comma-separated strings of Latitude,Longitude of points (eg '40.748785, -73.984902','40.742747, -73.972632');
//        {number} dp: number of decimal places to use in the returned distance
//Return: {number} Distance in m between point a and point b
//------------------------------------
function ZGeoDistance (pointa, pointb)
{
  var earthradius = 6378137; //Radius of the earth in m, 6378.137 in Km, 3963.191 in Miles, 6975215 in Yards
  var d2r = Math.PI / 180.0; //degree to radians , (x * d2r) = toRad(x)
  var reterr = '-';

  if (typeof pointa == 'undefined') {return reterr;}
  if (typeof pointb == 'undefined') {return reterr;}

  //trim whitespace and separate Latitude, Longitude
  var pa = pointa.replace(/\s/g, "").split(','); //split to pa[0] = Lat and pa[1] = Lon
  var pb = pointb.replace(/\s/g, "").split(','); //split to pb[0] = Lat and pb[1] = Lon
   
  //simple check of parameters
  if (pa.length != 2 || pb.length != 2 || isNaN(pa[0]) || isNaN(pa[1]) || isNaN(pb[0]) || isNaN(pb[1])) {return reterr;}

  dp = typeof(dp) == 'number' ? dp : typeof(dp) == 'string' && dp.replace(/^\s+|\s+$/g, '') != '' ? +dp : NaN;
  if (isNaN(dp) || dp < 0 || dp > 10) {dp = 0;}

  //calculate distance between point a and point b
  var lat1 = pa[0] * d2r, lon1 = pa[1] * d2r;
  var lat2 = pb[0] * d2r, lon2 = pb[1] * d2r;
  var dLat = lat2 - lat1;
  var dLon = lon2 - lon1;

  var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
          Math.cos(lat1) * Math.cos(lat2) *
          Math.sin(dLon / 2) * Math.sin(dLon / 2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  var dist = earthradius * c;

  return dist.toFixed(dp);
}
//\ZGeoDistance ------------------------------------

//------------------------------------
//ZGeoBearing (pointa, pointb, dp)
//Returns the (initial) bearing from point a to the point b in degrees
//see http://williams.best.vwh.net/avform.htm#Crs
//Params: {string} pointa,pointb: comma-separated strings of Latitude,Longitude of points (eg '40.748785, -73.984902','40.742747, -73.972632');
//        {number} dp: number of decimal places to use in the returned degree
//Return: {number} Initial bearing in degrees from North
//------------------------------------
function ZGeoBearing (pointa, pointb, dp)
{
  var d2r = Math.PI / 180.0; //degree to radians , (x * d2r) = toRad(x)
  var r2d = 180.0 / Math.PI; //radians to degree , (x * r2d) = toDeg(x)
  var reterr = '-';
 
  if (typeof pointa == 'undefined') {return reterr;}
  if (typeof pointb == 'undefined') {return reterr;}
  //trim whitespace and separate Latitude, Longitude
  var pa = pointa.replace(/\s/g, "").split(','); //split to pa[0] = Lat and pa[1] = Lon
  var pb = pointb.replace(/\s/g, "").split(','); //split to pb[0] = Lat and pb[1] = Lon
  //simple check of parameters
  if (pa.length != 2 || pb.length != 2 || isNaN(pa[0]) || isNaN(pa[1]) || isNaN(pb[0]) || isNaN(pb[1])) {return reterr;}

  dp = typeof(dp) == 'number' ? dp : typeof(dp) == 'string' && dp.replace(/^\s+|\s+$/g, '') != '' ? +dp : NaN;
  if (isNaN(dp) || dp < 0 || dp > 10) {dp = 10;}

  //calculate bearing from pointa to point b
  var lat1 = pa[0] * d2r, lat2 = pb[0] * d2r;
  var dLon = (pb[1] - pa[1]) * d2r;

  var y = Math.sin(dLon) * Math.cos(lat2);
  var x = Math.cos(lat1) * Math.sin(lat2) -
          Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
  var retvar = (Math.atan2(y, x) * r2d + 360) % 360;
 
  return retvar.toFixed(dp);
}
//\ZGeoBearing ------------------------------------

//------------------------------------
//ZGeoSpeed (pointa, pointb, timesec, dp)
//Returns the speed between point a and point b in m/sec
//Params: {string} pointa,pointb: comma-separated strings of Latitude,Longitude of points (eg '40.748785, -73.984902','40.742747, -73.972632');
//        {number} timesec: time in seconds between point a and point b
//        {number} dp: number of decimal places to use in the returned speed (default: 2)
//Return: {number} speed in m/sec between point a and point b
//------------------------------------
function ZGeoSpeed (pointa, pointb, timesec, dp)
{
  var earthradius = 6378137; //Radius of the earth in m, 6378.137 in Km, 3963.191 in Miles, 6975215 in Yards
  var d2r = Math.PI / 180.0; //degree to radians , (x * d2r) = toRad(x)
  var reterr = '-';

  if (typeof pointa == 'undefined') {return reterr;}
  if (typeof pointb == 'undefined') {return reterr;}

  //trim whitespace and separate Latitude, Longitude
  var pa = pointa.replace(/\s/g, "").split(','); //split to pa[0] = Lat and pa[1] = Lon
  var pb = pointb.replace(/\s/g, "").split(','); //split to pb[0] = Lat and pb[1] = Lon
   
  //simple check of parameters
  if (pa.length != 2 || pb.length != 2 || isNaN(pa[0]) || isNaN(pa[1]) || isNaN(pb[0]) || isNaN(pb[1])) {return reterr;}

  timesec = typeof(timesec) == 'number' ? timesec : typeof(timesec) == 'string' && timesec.replace(/^\s+|\s+$/g, '') != '' ? +timesec : NaN;
  if (isNaN(timesec) || timesec <= 0) {return reterr;}
 
  dp = typeof(dp) == 'number' ? dp : typeof(dp) == 'string' && dp.replace(/^\s+|\s+$/g, '') != '' ? +dp : NaN;
  if (isNaN(dp) || dp < 0 || dp > 10) {dp = 2;}

  //calculate distance between point a and point b
  var lat1 = pa[0] * d2r, lon1 = pa[1] * d2r;
  var lat2 = pb[0] * d2r, lon2 = pb[1] * d2r;
  var dLat = lat2 - lat1;
  var dLon = lon2 - lon1;

  var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
          Math.cos(lat1) * Math.cos(lat2) *
          Math.sin(dLon / 2) * Math.sin(dLon / 2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  var dist = earthradius * c;

  return (dist / timesec).toFixed(dp);
}
//\ZGeoSpeed ------------------------------------

//------------------------------------
//ZGeoCompassDir (deg, precision)
//Returns the compass directions from a given degree , e.g. N or NW or NNW ...
//Params: {number} deg: bearing in degrees from North
//        {number} precision: [default] (N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW), 2 (N,NE,E,SE,S,SW,W,NW), 1 (N,E,S,W)
//Return: {string} compass direction
//------------------------------------
function ZGeoCompassDir (deg, precision)
{
  var reterr = '-';
  deg = typeof deg == 'number' ? deg : typeof deg == 'string' && deg.replace(/\s/g, "") != '' ? +deg : NaN;
  if (isNaN(deg)) {return reterr;}
  deg = parseFloat(deg);

  var aDir = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'];

  precision = typeof precision == 'number' ? precision : typeof precision == 'string' && precision.replace(/\s/g, "") != '' ? +precision : 3;
  switch(precision) {
    case 1:
      return aDir[Math.floor((deg + 45.0) / 90.0) * 4]; //N,E,S,W,N
    case 2:
      return aDir[Math.floor((deg + 22.5) / 45.0) * 2]; //N,NE,E,SE,S,SW,W,NW,N
    default:
      return aDir[Math.floor((deg + 11.25) / 22.5)]; //N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW,N
  }
}
//\ZGeoCompassDir ------------------------------------

//=====================================

Vladimir Oz

unread,
Aug 19, 2012, 2:02:28 PM8/19/12
to tas...@googlegroups.com
wow. cool.
I've realize it in Tasker task, already. Now, You show me the JS code. But I believe, that built-in functions would be faster than these ones..... I hope I'm right.
I think JS piece of code is faster than Tasker's one because of queue. JS code runs as one action while tasker's actions are one by one with others.

Ok. Thank You for suggestion. It'll be useful.

madmax

unread,
Oct 23, 2012, 4:06:10 PM10/23/12
to tas...@googlegroups.com
thank you for this script

I changed the variables for the dictance "global var p2 = ('LOC');"
ZGeoDistance me bine displays the distance of p1 and p2
So far all goes well the

by cons I want to get the value in tasker ZGeoDistance ZGeodistance% but does not
is this possible? If yes how

thank you bcp

Le lundi 22 octobre 2012 13:47:21 UTC+2, madmax a écrit :
hello 

I want an app that launches create and along the radius of the place where we find an action is taken

for actions no problem but not the obvious place

as a context you can choose the place and its radius but an app with no context so I pass the variable% LOC who knows with the GPS longitude and latitude but I would have an effect on a radius of about 200m

So my app is

gps on
if% LOC-coordinate is (this is where I would put a radius)
end if
1 spot
spot output
* gps off
kill applicable
Reply all
Reply to author
Forward
0 new messages