GPS speed

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
DukeUK
Posts: 23
Joined: Sun Dec 06, 2009 5:55 pm

GPS speed

Post by DukeUK » Sun Apr 28, 2013 2:36 pm

I’m just experimenting with the mobile gps functions and I’ve hit a problem in getting the “speed” from the Location data.

The code is basically as follows:

Code: Select all

mobileStartTrackingSensor "location", true
 put mobileSensorReading ("location",true) into geodata
   put geodata["latitude"] into tlat
   put geodata["longitude"] into tlong
   put geodata["horizontal accuracy"] into tHA
   put geodata["altitude"] into tAlt
   put geodata["vertical accuracy"] into tVA
   put geodata["timestamp"] into ttime
   put geodata["speed"] into tspeed
I’m running LC6 and in the simulator (version 5 and later) this all seams to work OK and all the fields are filled in with the data from the above.

However, when I try it on a real device, everything works apart from the speed, which remains blank. The horizontal accuracy figure is quite poor on the real device where I’ve tested it (65m). I don’t know whether this is causing the problem or whether it’s something wrong with the coding, or whether LC doesn't get the "speed".

I’ve read about the “speed” not being obtainable with LC but I can’t find any reference to this in the release notes for version 6.0. That doesn’t sound like its the problem though if it works OK in the simulator?

I did get it to work by calculating the distance from the latitude / longitude values and dividing it by the time, but I though if I could get the “speed” directly that would be much better.

Any ideas on what could be wrong??

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: GPS speed

Post by Dixie » Sun Apr 28, 2013 3:56 pm

Hi..

The 'speed' is not available in iOS, as you have realised you have to calculate it yourself... It is something that I have been doing lately and wonder how you have been doing it ? Are you using the 'haversine' formula or calling the distances from the google api ?

Dixie

DukeUK
Posts: 23
Joined: Sun Dec 06, 2009 5:55 pm

Re: GPS speed

Post by DukeUK » Sun Apr 28, 2013 4:29 pm

Hi Dixie

Thanks for that.

The thought had crossed my mind.

What through me off track was that when I ran it in the simulator the speed field was updating OK. I can't be sure the numbers were right, but they were of the right sort of order for the various modes of travel.

I've tried using Haversine, Spherical Cosine and the Equirectangular approximation and the results come out pretty much identical for the distances I've tested them over (they are the same to 6 or 7 decimal places when working out the distance in km, over distances of a few km. For these distances I think the Equirectangular approximation is as good a method as any. It only uses one trig function and seams to give accurate results. I think the errors will come from the accuracy of the GPS coordinates rather than the distance calculation itself.

I will check it over a longer distance when I get the chance (I don't get out much).

I've checked the distances using google maps and the results are spot on. I've not tried it the other way round though, but I would expect the results to be very similar.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: GPS speed

Post by Dixie » Sun Apr 28, 2013 5:54 pm

DukeUK...

I have attached a stack, this is just for the desktop, that calculates the distances from where I am in the UK to each of the 2983 postcode areas of the UK... clicking the button, unimaginatively named 'button' will order the postcodes in order ascending... the last two items being the distance I am away from each postcode by miles and kilometres.. it is pretty quick...

This is what I started off with... using 'haversine' allows the calculation to be done within the stack, instead of waiting for the return from the google api which slows things down to a crawl. It is also, in my opinion, the only way to go if you are wanting to be updated with 'speed' in small time intervals... as getting the reading from the mobilesensor is quick and also seems very forgiving about how strong the connection you have is to the internet on the iphone..

Hope it is of interest...

Dixie
Attachments
haversine.zip
(30.4 KiB) Downloaded 285 times

Post Reply