mobileSensorAvailable ("location")

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: mobileSensorAvailable ("location")

Post by jacque » Fri Jan 29, 2016 5:51 pm

If the answer dialog shows the correct message, why put just line 2 of it into the field? I still don't know why you're getting the "false" but apparently it's in the second line.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Fri Jan 29, 2016 5:56 pm

Let me rephrase - answer shows the correct message including messaging protocol -

i.e.

"LOCA [Lat] [Long]
Name: Message"

of which line 2 is the bit to be shown as a message. LOCA is the message type, and the location data is used for the calculation. But I don't want LOCA and the location to be shown in the actual message displayed.

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Sat Jan 30, 2016 3:08 pm

Lordy...

Code: Select all

if tTheirLat + (400/6911) >= tMyLat and tMyLat >= tTheirLat - (400/6911) then #If we're within 2 miles, show the message
   #Longitude varies with distance from the equator – this a calculation to work out degrees vs miles
   put "TEST" && tMessage && return after field "displayMessage"
   if tTheirLong + ((400/6911) * cos((tMyLat + tTheirLat)/2)) >= tMyLong then
      put "Success!" & return after field "displayMessage" 
         if tMyLong >= tTheirLong - ((400/6911) * cos((tMyLat + tTheirLat)/2)) then
            put line 2 of tMessage and return after field "displayMessage"
            end if

end if
 end if
Gives me the TEST message fine.

Gives me 'Success!' fine.

Then gives me 'false'.

So it seems to be:
if tMyLong >= tTheirLong - ((400/6911) * cos((tMyLat + tTheirLat)/2)) then

That is giving false. But I don't know why. I don't know what further changes I can make.

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Sat Jan 30, 2016 6:19 pm

Different permutations give me different responses but no solution.

No matter what I do, tMessage seems to be correct EXCEPT following the Longitude calculations and in the form of 'put... after'. 'answer' gives it correctly. There doesn't seem to be any problem with the calculation itself, because it can do other stuff after the calculation with no issues.

Something is interacting with something else and I can't quite pin down what.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: mobileSensorAvailable ("location")

Post by Dixie » Sat Jan 30, 2016 6:23 pm

What is (400/6911) ?.. what does it represent ?

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Sat Jan 30, 2016 7:08 pm

Dixie wrote:What is (400/6911) ?.. what does it represent ?
400/6911 is 2 miles of latitude.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: mobileSensorAvailable ("location")

Post by Dixie » Sat Jan 30, 2016 7:21 pm

Ok... What exactly are you trying to do ?... Are you trying to find the distance between two sets of lat/long coordinates ?

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Sat Jan 30, 2016 8:56 pm

The code in question receives a message from the server which includes a set of coordinates in latitude and longitude.

The client is supposed to work out whether those coordinates are within two miles of the client's coordinates, and if they are, post the message, and if not, NOT post the message.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: mobileSensorAvailable ("location")

Post by Dixie » Sat Jan 30, 2016 9:24 pm

Make a new Card
Make three fields
Make a button...

put a set of coordinates into fld 1
put a set of coordinates into fld 2

put the following into the script of the button...

Code: Select all

on mouseDown
   /*lat/long from first set of coordinates */
   put item 1 of fld 1 * pi/180 into lat1
   put item 2 of fld 1 * pi/180 into lon1
   /*lat/long from second set of coordinates */
   put item 1 of fld 2 * pi/180 into lat2
   put item 2 of fld 2 * pi/180 into lon2
   
   set numberformat to 0.00
   put (sin((lat2 -lat1)/2))^2 + cos(lat1) * cos(lat2) * (sin((lon2 - lon1)/2))^2 into a
   put 2 * atan2( sqrt(a), sqrt(1-a) ) into c
   put 6373 * c into klicks
   put 3961 * c into miles
   put klicks && "Kilometres" && "/" && miles && "miles" into fld 3
end mouseDown
The resullt is hown in fld 3... note that the distances are in a 'straight line' between to two locations

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Sun Jan 31, 2016 12:31 am

Wow, uh, what am I looking at here? My maths is confined to what I can sit down and start from scratch, it's a little beyond me.

Is it calculating the distance between two points?

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Sun Jan 31, 2016 4:48 pm

OK, so having worked that out, I've tried the new script in the following format:

Code: Select all

case LOCA
   if lMobileLoc is true then
      set the itemDelimiter to ","
         put item 1 of uMyLocation * pi/180 into tMyLat
   put item 2 of uMyLocation * pi/180 into tMyLong
   /*lat/long from second set of coordinates */
   put item 2 of data * pi/180 into tTheirLat
   put item 3 of data* pi/180 into tTheirLong
   
   set numberformat to 0.00
   put (sin((tTheirLat -tMyLat)/2))^2 + cos(tMyLat) * cos(tTheirLat) * (sin((tTheirLong - tMyLong)/2))^2 into a
   put 2 * atan2( sqrt(a), sqrt(1-a) ) into c
   put 6373 * c into klicks
   put 3961 * c into miles
  

set the backgroundcolor of button "Location" to green
 
set the label of button "Location" to uMyLocation

 put miles after field "displayMessage"
if miles < 2 then
   put line 2 of data and return after field "displayMessage"
   set the backgroundcolor of button "Location" to yellow
   answer line 2 of data
   end if
 
 
break
Now, I got this to do the following things:

-Turn button 'Location' to yellow.
-Post the miles (0.00 since it's checking its own message), followed by the word 'false'.

So now I've got to the same point as I got to with my previous code. I can get it to agree that miles < 2. I can get it to react to that fact. But I can't get it to post a message other than 'false', nor the 'return' in that line.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: mobileSensorAvailable ("location")

Post by Dixie » Sun Jan 31, 2016 6:26 pm

Use '&' instead of 'and'
I think data is a reserved word... try something like thedata for the variable name...
Spend time reading the 'user manual'...:-(

Code: Select all

 if miles < 2 then
      put line 2 of thedata & return after field "displayMessage"
      set the backgroundcolor of button "Location" to yellow
      answer line 2 of thedata
   end if

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Sun Jan 31, 2016 6:43 pm

Data works fine right up until this little if clause. I was using tMessage before, I've swapped back to it to avoid using data, but it hasn't made a difference.

I've put in 'answer' at every point, now.

Code: Select all

case LOCA
   if lMobileLoc is true then
      put word 1 of uMyLocation * pi/180 into tMyLat
      answer word 1 of uMyLocation
      put word 2 of uMyLocation * pi/180 into tMyLong
      answer word 2 of uMyLocation
      put word 2 of tMessage * pi/180 into tTheirLat
      answer word 2 of tMessage
      put word 3 of tMessage * pi/180 into tTheirLong
      answer word 3 of tMessage
   
   set numberformat to 0.00
   put (sin((tTheirLat - tMyLat)/2))^2 + cos(tMyLat) * cos(tTheirLat) * (sin((tTheirLong - tMyLong)/2))^2 into a
   put 2 * atan2( sqrt(a), sqrt(1-a) ) into c
   put 6373 * c into klicks
   put 3961 * c into miles
   answer miles

if miles < 2 then
   put line 2 of tMessage and return after field "displayMessage"
   set the backgroundcolor of button "Location" to yellow
   answer line 2 of tMessage
   set the label of button "Location" to miles
   end if
First answer gives a latitude. GOOD.
Second answer gives a longitude. GOOD.
Third answer gives a latitude. GOOD.
Fourth answer gives a longitude. GOOD.
Fifth answer gives 0.00. GOOD.
Sixth answer gives "[Name]: [Message]". GOOD.

...And then it puts 'false' (with no return) into the displayMessage field.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: mobileSensorAvailable ("location")

Post by Dixie » Sun Jan 31, 2016 6:47 pm

Well, what do you expect ?.. the variable tMessage as you have populated it does not have two linea !

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: mobileSensorAvailable ("location")

Post by A1Qicks » Sun Jan 31, 2016 6:56 pm

Yes, it does. It has:

"LOCA [Lat] [Long]
Name: Message"

It answers the second line no problem when I tell it:

"answer line 2 of tMessage"

It's only when putting it into displayMessage that it screws up.

EDIT:
I tried putting
"put tMessage after field "displayMessage"
As well as the 'line 2' option, just to check. Both give 'false'. So now I've got 'falsefalse'.

Post Reply