Writing and sorting list advice SOLVED
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Writing and sorting list advice SOLVED
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
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.
Re: Writing and sorting list advice
So this is where I'm at at the moment:
Start Button Script:
Stop Button Script:
Card Script:
It doesn't work but I can't work out why..
Start Button Script:
Code: Select all
on mouseUp
mobileStartTrackingSensor "location"
end mouseUp
Code: Select all
on mouseUp
mobileStopTrackingSensor "location"
end mouseUp
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Writing and sorting list advice
Hi calmrr3,
Try putting allXCoords into a field so you can see what you are getting.
Also when working with mobile always include this;
Mobile loves to fail silently.
Simon
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
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Writing and sorting list advice
Hi,
Thanks for your reply!
So I added the line:
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
Thanks for your reply!
So I added the line:
Code: Select all
put allXCoords into field "allXCoordsField"
It's probably a mistake in my code - still getting my head round livecode.
Thanks
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Writing and sorting list advice
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
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!
-
- Posts: 192
- Joined: Tue Mar 11, 2014 12:57 pm
Re: Writing and sorting list advice
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.
Try answer or a field.
Re: Writing and sorting list advice
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
Thanks again
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Writing and sorting list advice
Code: Select all
global MYaltitude
global MYlatitude
global MYlongitude
global counterVal
put 1 into counterVal
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!
Re: Writing and sorting list advice
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):
Start Button Script (Objective = Starts tracking the location):
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):
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
Code: Select all
on mouseUp
put 1 into counterVal
mobileStartTrackingSensor "location"
end mouseUp
Code: Select all
on mouseUp
mobileStopTrackingSensor "location"
sort items of allXCoords ascending numeric
put allXCoords into field "Field2"
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Writing and sorting list advice
You are missing the global declaration in both the buttons.
This line should be in the stop button
And is actually deletes the last comma.
And don't forget the GPS setting in the standalone.
Simon
Code: Select all
global counterVal
on mouseUp
put 1 into counterVal
mobileStartTrackingSensor "location"
end mouseUp
Code: Select all
delete char -1 of allXCoords // deletes first 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!
Re: Writing and sorting list advice
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:
Start Button:
Stop Button:
Thanks again
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
Code: Select all
global counterVal
on mouseUp
mobileStartTrackingSensor "location"
put 1 into counterVal
end mouseUp
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Writing and sorting list advice
Attached it a working stack (not as pretty as yours).
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
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!
-
- VIP Livecode Opensource Backer
- Posts: 135
- Joined: Mon Jul 31, 2006 1:39 am
- Location: New Zealand, Australia, Germany, Japan
- Contact:
Re: Writing and sorting list advice
You also may want to include the mobile tracking error code in your card or stack script, as below:
Good luck.
cheers
Alan
Code: Select all
on trackingError pSensor, pError
answer "There was an error with sensor" && pSensor
end trackingError
cheers
Alan
Re: Writing and sorting list advice SOLVED
Thanks! I've managed to get it working now.