Page 1 of 1
Writing and sorting list advice SOLVED
Posted: Wed Jan 14, 2015 2:55 pm
by calmrr3
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
Re: Writing and sorting list advice
Posted: Wed Jan 14, 2015 8:50 pm
by calmrr3
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..
Re: Writing and sorting list advice
Posted: Wed Jan 14, 2015 9:10 pm
by Simon
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
Re: Writing and sorting list advice
Posted: Wed Jan 14, 2015 9:21 pm
by calmrr3
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
Re: Writing and sorting list advice
Posted: Wed Jan 14, 2015 11:15 pm
by Simon
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
Re: Writing and sorting list advice
Posted: Thu Jan 15, 2015 1:14 am
by newtronsols
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.
Re: Writing and sorting list advice
Posted: Thu Jan 15, 2015 12:34 pm
by calmrr3
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
Re: Writing and sorting list advice
Posted: Thu Jan 15, 2015 9:06 pm
by Simon
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
Re: Writing and sorting list advice
Posted: Thu Jan 15, 2015 9:53 pm
by calmrr3
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

Re: Writing and sorting list advice
Posted: Fri Jan 16, 2015 12:11 am
by Simon
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
Re: Writing and sorting list advice
Posted: Fri Jan 16, 2015 11:31 am
by calmrr3
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
Re: Writing and sorting list advice
Posted: Sat Jan 17, 2015 3:35 am
by Simon
Attached it a working stack (not as pretty as yours).
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
Re: Writing and sorting list advice
Posted: Sat Jan 17, 2015 10:40 am
by strongbow
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
Re: Writing and sorting list advice SOLVED
Posted: Sat Jan 17, 2015 1:02 pm
by calmrr3
Thanks! I've managed to get it working now.