iPhone GPS Question

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
CoreySchroeder
Posts: 26
Joined: Mon Sep 14, 2015 4:31 am

iPhone GPS Question

Post by CoreySchroeder » Sat Oct 10, 2015 7:43 pm

Hi there,

I'm fairly new to LiveCode, and very new to iOS Dev.

I'd like to see if it would be possible to check the current speed the phone is traveling?
Like, if your phone is in your car with you, would it be possible to see the current speed you are traveling?

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

Re: iPhone GPS Question

Post by Dixie » Sun Oct 11, 2015 1:04 am

Have a look at 'mobileSensorReading' in the dictionary...

This is from the iOS notes that liveCode used to produce... 'speed' and 'course' are mentioned here. I have used it before and it worked, though I seem to remember it took a while before anything was returned regarding speed and course... mmm... but speed and course are now not mentioned in the dictionary... You'll have to ask the mothership whether this has been deprecated or not... err... or try it yourself and see ... :-)

mobileSensorReading(sensor, [detailed])
The boolean parameter detailed determines the amount of detail present in the data returned. If this is false, the data returned is a comma separated list. If true, an array is returned. By default, detailed is false.

The data returned depends upon the sensor.
Location - a comma separated list of the latitude, longitude and altitude of the device. If detailed is true an array containing the keys latitude, longitude, altitude, time stamp, horizontal accuracy, vertical accuracy, speed and course is returned.

If the latitude and longitude could not be measured, those values together with the horizontal accuracy key will not be present. If the altitude could not be measured, that value together with the vertical accuracy will not be present.

mtalluto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 125
Joined: Tue Apr 11, 2006 7:02 pm
Location: Seattle, WA
Contact:

Re: iPhone GPS Question

Post by mtalluto » Mon Apr 20, 2020 10:24 pm

This is possible now. I do not know which version of LC getting the speed was released.

Sample code:

on openCard
if the platform is "iphone" then
mobileStartTrackingSensor "location", false
end if
end openCard

command locationChanged
local tSensorDataA, tSpeed

--RETURN A STRING WITH THE CURRENT LATITUDE, LONGITUDE AND ALTITUDE
put mobileSensorReading("location",true) into tSensorDataA
if tSensorDataA is empty then
put "No data" into fld "speed"
exit locationChanged
end if

put tSensorDataA["speed"] into tSpeed --output is in meters per second
if tSpeed is empty or tSpeed = "0.0" then
set numberFormat to "x"
put 0 into tSpeed
put "0" into fld "speed"
exit locationChanged
else
set numberFormat to "x.x"
end if

put tSpeed * 2.237 into tSpeed --convert meters per second to miles per hour
if tSpeed > sMaxSpeed then put tSpeed into sMaxSpeed
put "Max speed:" && max(tSpeed,sMaxSpeed) into fld "max speed"

put tSpeed into fld "speed"
end locationChanged
Mark Talluto
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com

Post Reply

Return to “iOS Deployment”