Copying Arrays from GPS data

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Wild_Eep
Posts: 2
Joined: Sat Dec 10, 2011 7:20 am

Copying Arrays from GPS data

Post by Wild_Eep » Sat Dec 10, 2011 7:35 am

Hi all,

I followed the tutorial about receiving GPS coordinates from the iOS: "How do I use CoreLoction with iOS"

All of that worked properly on the first run!

So I was thinking about extending the features a bit, calculating the difference in lat/lon based on the most recent two sets of lat/long received.

based on the article, I already had an array called tLocation. It has six elements (lat, lon, horizontal accuracy, altitude, vertical accuracy, and timestamp)

I put those elements into tLocation["now"]. I wanted to copy them into tLocation["then"], and then overwrite what was in tLocation["now"] with the newest location data.

Here's the code I'm using:

Code: Select all

on locationChanged
   
   --get new location
   put empty into field "monitor"
   local tLocation
   put iphoneCurrentLocation() into tLocation["now"]
   
   --display returned location
   put displayArrayData(tLocation) into field "monitor"
   put tLocation["now"]["latitude"] into fld "Lat"
   put tLocation["now"]["longitude"] into fld "Long"
   put tLocation["now"]["horizontal accuracy"] into fld "HA"
   put tLocation["now"]["altitude"] into fld "Alt"
   put tLocation["now"]["vertical accuracy"] into fld "VA"
   put tLocation["now"]["timestamp"] into tStamp
   
   convert tStamp to short date and long time
   put tStamp into fld "Time"
   
   
   --push new location into old location's slot
   put tLocation["now"] into tLocation["then"]
For debugging purposes, I'm dumping the array into a textbox named "monitor", but I only see tLocation["now"], without the additional tLocation["then"] that I'm expecting.

I'm pretty confident that I have the syntax right for copying one part of an array into another part, but it's just not working here.

Anyone have some ideas? I'm new to LiveCode, and surprised that I'm bumping my head on this problem.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Copying Arrays from GPS data

Post by bn » Sat Dec 10, 2011 6:39 pm

Hi Wild,

the problem of iOS and Livecode is that a script error often fails silently. To catch errors you can add a field to your card called e.g. field "fErr"
and place a handler in the card script

Code: Select all

on errorDialog
   put the params into field "fErr"
end errorDialog
although the params are often not very informative it at least alerts to an execution error.

Actually I find it helpful to implement this during the development of an iOS app. It saves a lot of head scratching. Later remove it. You can implement the field as a group with background behavior = true. That way the field "fErr" will be on every card you create and later you can remove the background group easily. And in that case you would place the on errorDialog handler in the stack script from where it also is easily removed.

Also you might want to post the script of your function displayArrayData

Kind regards

Bernd

Post Reply