mobileSensorAvailable ("location")
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: mobileSensorAvailable ("location")
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
HyperActive Software | http://www.hyperactivesw.com
Re: mobileSensorAvailable ("location")
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.
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.
Re: mobileSensorAvailable ("location")
Lordy...
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.
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 '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.
Re: mobileSensorAvailable ("location")
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.
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.
Re: mobileSensorAvailable ("location")
What is (400/6911) ?.. what does it represent ?
Re: mobileSensorAvailable ("location")
400/6911 is 2 miles of latitude.Dixie wrote:What is (400/6911) ?.. what does it represent ?
Re: mobileSensorAvailable ("location")
Ok... What exactly are you trying to do ?... Are you trying to find the distance between two sets of lat/long coordinates ?
Re: mobileSensorAvailable ("location")
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.
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.
Re: mobileSensorAvailable ("location")
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...
The resullt is hown in fld 3... note that the distances are in a 'straight line' between to two locations
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
Re: mobileSensorAvailable ("location")
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?
Is it calculating the distance between two points?
Re: mobileSensorAvailable ("location")
OK, so having worked that out, I've tried the new script in the following format:
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.
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
-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.
Re: mobileSensorAvailable ("location")
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'...
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
Re: mobileSensorAvailable ("location")
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.
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.
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
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.
Re: mobileSensorAvailable ("location")
Well, what do you expect ?.. the variable tMessage as you have populated it does not have two linea !
Re: mobileSensorAvailable ("location")
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'.
"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'.