Writing and sorting list advice SOLVED

Getting into LiveCode for iOS? Ask your questions here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Writing and sorting list advice SOLVED

Post by calmrr3 » Wed Jan 14, 2015 2:55 pm

Hello,

I am trying to figure out the best way to do the following on an iPhone:


Detect location change (latitude and longitude only).
Each time there is a change in location, add the X coordinate to a list & add the Y location to a list. Add the X and Y coordinates to list. So i would have the following 3 lists:

X coordinates only
Y coordinates only
X,Y coordinates

When the user stops tracking I want to be able to sort the X coordinate list and the Y coordinate list numerically, giving me the maximum and minimum values from each so that I can then remap the values to fit within the screen. And then using the unsorted X,Y list, plot the GPS points.

I am unsure if I should be using an array, a text file or a data grid (or something else?) and also the best way to go about setting this up.

I have locationChanged on the card and a start and stop tracking button.


Thank you
Last edited by calmrr3 on Sat Jan 17, 2015 1:03 pm, edited 1 time in total.

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Writing and sorting list advice

Post by calmrr3 » Wed Jan 14, 2015 8:50 pm

So this is where I'm at at the moment:

Start Button Script:

Code: Select all

on mouseUp
   mobileStartTrackingSensor "location"
end mouseUp
Stop Button Script:

Code: Select all

on mouseUp
   mobileStopTrackingSensor "location"
end mouseUp
Card Script:

Code: Select all

global MYaltitude
global MYlatitude
global MYlongitude
global counterVal
put 1 into counterVal

on locationChanged pLatitude, pLongitude, pAltitude
   
   add 1 to counterVal
   
   put counterVal into field "FieldCount"
   
   put pAltitude into MYaltitude
   put pLatitude into MYlatitude
   put pLongitude into MYlongitude

 local allXCoords
   
   repeat while the number of items in allXCoords < 10 // 10 = Time Period / Interval
    
    put MYlatitude & comma after allXCoords
   
   end repeat

   delete char -1 of allXCoords
   sort items of allXCoords ascending numeric
   put allXCoords into msg

end locationChanged pLatitude, pLongitude, pAltitude
It doesn't work but I can't work out why..

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Writing and sorting list advice

Post by Simon » Wed Jan 14, 2015 9:10 pm

Hi calmrr3,
Try putting allXCoords into a field so you can see what you are getting.

Also when working with mobile always include this;

Code: Select all

on errorDialog pExecutionError, pParseError
answer "An error occurred on line: " & item 2 of line 1 of pExecutionError & cr & pExecutionError
end errorDialog
Mobile loves to fail silently.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Writing and sorting list advice

Post by calmrr3 » Wed Jan 14, 2015 9:21 pm

Hi,

Thanks for your reply!

So I added the line:

Code: Select all

put allXCoords into field "allXCoordsField"
However, when I press Start nothing happens in either of the fields (this field or the counter field).

It's probably a mistake in my code - still getting my head round livecode.

Thanks

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Writing and sorting list advice

Post by Simon » Wed Jan 14, 2015 11:15 pm

Is this being tested on a real device?
on the sim I think under "Window" you have Location and then a bunch of styles like "riding bike" "walking".

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: Writing and sorting list advice

Post by newtronsols » Thu Jan 15, 2015 1:14 am

As I use LC with Windows & Android I noticed 'msg' - as I've never used. I checked it says Linux, Mac, Windows - but not iphone/Android.
Try answer or a field.

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Writing and sorting list advice

Post by calmrr3 » Thu Jan 15, 2015 12:34 pm

Hi,

I am currently testing it on the simulator and still nothing is appearing in the fields when I click start.

I have removed the line with 'msg' and changed it to

Code: Select all

put allXCoords into field "allXCoordsField"

Thanks again

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Writing and sorting list advice

Post by Simon » Thu Jan 15, 2015 9:06 pm

Code: Select all

global MYaltitude
global MYlatitude
global MYlongitude
global counterVal
put 1 into counterVal
That "put 1 into counterVal" shouldn't be there, probably you should put it into the Start button.

Oh, and in the sim Location is under Debug but it seems you must have the stack open for it to show City Bicycle Ride, City Run, etc. Errr... they only show if you are or have requested location information.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Writing and sorting list advice

Post by calmrr3 » Thu Jan 15, 2015 9:53 pm

Hi,

Yes, I am using the city run option on the simulator.

So this is where I am at now:

Card Script (Objective = Count number of location changes & record X coordinate at each location change):

Code: Select all

global MYaltitude
global MYlatitude
global MYlongitude
global counterVal
global allXCoords

on locationChanged pLatitude, pLongitude, pAltitude
   
   if the number of items in allXCoords < 10 then // 10 = Total number of location changes
   
   add 1 to counterVal
   put counterVal into field "FieldCount" // Counts location changes
   
   put pAltitude into MYaltitude
   put pLatitude into MYlatitude
   put pLongitude into MYlongitude
   
   put MYlatitude & comma after allXCoords
   delete char -1 of allXCoords // deletes first comma
   
end if
end locationChanged pLatitude, pLongitude, pAltitude

on errorDialog pExecutionError, pParseError
answer "An error occurred on line: " & item 2 of line 1 of pExecutionError & cr & pExecutionError
end errorDialog

     
Start Button Script (Objective = Starts tracking the location):

Code: Select all

on mouseUp
   put 1 into counterVal
   mobileStartTrackingSensor "location"
end mouseUp
Stop Button Script (Objective = Stop tracking the location, Sort the recorded X coordinates and then put the ordered list of numbers into a field as a list):

Code: Select all

on mouseUp
   
   mobileStopTrackingSensor "location" 
   
      sort items of allXCoords ascending numeric
      put allXCoords into field "Field2"
   
end mouseUp
Image

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Writing and sorting list advice

Post by Simon » Fri Jan 16, 2015 12:11 am

You are missing the global declaration in both the buttons.

Code: Select all

global counterVal
on mouseUp
   put 1 into counterVal
   mobileStartTrackingSensor "location"
end mouseUp
This line should be in the stop button

Code: Select all

delete char -1 of allXCoords // deletes first comma
And is actually deletes the last comma.

And don't forget the GPS setting in the standalone.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Writing and sorting list advice

Post by calmrr3 » Fri Jan 16, 2015 11:31 am

Hi,

So i've made all the suggested changes but still nothing is appearing in either of the fields..

Here is the current script:

Card:

Code: Select all

global MYaltitude
global MYlatitude
global MYlongitude
global counterVal
global allXCoords

on locationChanged pLatitude, pLongitude, pAltitude
   if the number of items in allXCoords < 10 then // 10 = Total number of location changes
     put counterVal into field "FieldCount" // Counts location changes
     add 1 to counterVal
     put pAltitude into MYaltitude
     put pLatitude into MYlatitude
     put pLongitude into MYlongitude
     put MYlatitude & comma after allXCoords
   end if
end locationChanged pLatitude, pLongitude, pAltitude

on errorDialog pExecutionError, pParseError
   answer "An error occurred on line: " & item 2 of line 1 of pExecutionError & cr & pExecutionError
end errorDialog

Start Button:

Code: Select all

global counterVal

on mouseUp
   mobileStartTrackingSensor "location"
   put 1 into counterVal
end mouseUp
Stop Button:

Code: Select all

global counterVal
global allXCoords

on mouseUp
   mobileStopTrackingSensor "location" 
   put allXCoords into field "Field2"
   delete char -1 of allXCoords // deletes last comma
   sort items of allXCoords ascending numeric
end mouseUp
Thanks again

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Writing and sorting list advice

Post by Simon » Sat Jan 17, 2015 3:35 am

Attached it a working stack (not as pretty as yours).
gps_thingy.zip
lc 6.6.5
(1.7 KiB) Downloaded 67 times
Replaced the comma's with cr just for readability.

If that stack doesn't work then it may be Location under Debug should be changed. Look for the little arrow that turns on in the sim showing location services are on.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 127
Joined: Mon Jul 31, 2006 1:39 am
Location: New Zealand, Australia, Germany, Japan
Contact:

Re: Writing and sorting list advice

Post by strongbow » Sat Jan 17, 2015 10:40 am

You also may want to include the mobile tracking error code in your card or stack script, as below:

Code: Select all

on trackingError pSensor, pError
   answer "There was an error with sensor" && pSensor
end trackingError
Good luck.

cheers

Alan

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Writing and sorting list advice SOLVED

Post by calmrr3 » Sat Jan 17, 2015 1:02 pm

Thanks! I've managed to get it working now.

Post Reply

Return to “iOS Deployment”