Page 1 of 1
Mobile android standalone initial error getting location
Posted: Tue Feb 04, 2014 1:14 pm
by howardBUSMuQ1
Can anyone explain why - when a button has a script including the code below - a standalone Android app will always return an empty message the first time it is pressed, but subsequently will return the latitude?
on mouseUp
if the environment is "mobile" then
mobileStartTrackingSensor "location"
put mobileCurrentLocation() into theLocation
answer theLocation["latitude"]
end if
end mouseUp
Re: Mobile android standalone initial error getting location
Posted: Tue Feb 04, 2014 2:22 pm
by Dixie
It takes a little time for your location to be determined when you call the 'location' sensor. Try putting this into your openStack handler and your problem should go away...
I call mobileStartTrackingSensor "location" in the openStack handler... I also have in the stack script
Code: Select all
on locationChanged latitude, longitude
/* update the custom property 'theCurrentLocation' as the physical location of the device changes */
set the theCurrentLocation of this stack to latitude & comma & longitude
end locationChanged
and finally, in the openCard handler
Code: Select all
/* wait until the location of the mobile device has been determined */
repeat forever
wait 0 millisecs with messages
if the theCurrentLocation of this stack is not empty then
exit repeat
end if
end repeat
be well
Re: Mobile android standalone initial error getting location
Posted: Mon Feb 10, 2014 1:05 am
by howardBUSMuQ1
Thanks so much, Dixie. If I use a 'repeat forever' as you suggest in the card handler, am I not risking the user being stuck in limbo if - for whatever reason - the mobile can't find the location?
Re: Mobile android standalone initial error getting location
Posted: Mon Feb 10, 2014 10:37 am
by Dixie
howard..
if you wanted to do so in the case of waiting for the lat/long, you could do something like this...
Code: Select all
put 0 into timeOut
repeat forever
wait 0 millisecs with messages
if the theCurrentLocation of this stack is not empty then
exit repeat
end if
if timeOut = 20000 then
answer "I'm tired of waiting"
quit
end if
add 1 to timeOut
end repeat
Re: Mobile android standalone initial error getting location
Posted: Mon Feb 10, 2014 10:49 am
by howardBUSMuQ1
Dixie,
Thank you for spending time on this. Very generous. If ever you need advice from someone who doesn't know anything, you know who to call.
Cheers.