Mobile android standalone initial error getting location

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
howardBUSMuQ1
Posts: 10
Joined: Fri Mar 01, 2013 4:28 am

Mobile android standalone initial error getting location

Post by howardBUSMuQ1 » Tue Feb 04, 2014 1:14 pm

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

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

Re: Mobile android standalone initial error getting location

Post by Dixie » Tue Feb 04, 2014 2:22 pm

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

howardBUSMuQ1
Posts: 10
Joined: Fri Mar 01, 2013 4:28 am

Re: Mobile android standalone initial error getting location

Post by howardBUSMuQ1 » Mon Feb 10, 2014 1:05 am

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?

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

Re: Mobile android standalone initial error getting location

Post by Dixie » Mon Feb 10, 2014 10:37 am

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

howardBUSMuQ1
Posts: 10
Joined: Fri Mar 01, 2013 4:28 am

Re: Mobile android standalone initial error getting location

Post by howardBUSMuQ1 » Mon Feb 10, 2014 10:49 am

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.

Post Reply