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
			
			
									
									
						Mobile android standalone initial error getting location
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
- 
				howardBUSMuQ1
- Posts: 10
- Joined: Fri Mar 01, 2013 4:28 am
Re: Mobile android standalone initial error getting location
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
and finally, in the openCard handler
be well
			
			
									
									
						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 locationChangedCode: 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- 
				howardBUSMuQ1
- Posts: 10
- Joined: Fri Mar 01, 2013 4:28 am
Re: Mobile android standalone initial error getting location
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
howard..
if you wanted to do so in the case of waiting for the lat/long, you could do something like this...
			
			
									
									
						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
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.
			
			
									
									
						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.
