iOS Question Location.Time GPS or IOS ?

cooperlegend

Active Member
Licensed User
Longtime User
My App on Android uses GPS Time from Location.Time which works fine.

But the same App on iOS using Location.Time seems to return the device time not the time returned from GPS, Is this my device or am I missing something ?

Thanks in advance for your help
 

Filippo

Expert
Licensed User
Longtime User
How do you do, like this?
B4X:
Sub GPS1_LocationChanged (Location1 As Location)
    If Location1.Time > 0 Then
        gpsTime = DateTime.Now - Location1.Time
    End If
End Sub

Sub GpsTimer_Tick
    Dim Time As Long
    Time = DateTime.Now - gpsTime
    lblClock.Text = DateTime.Time(Time)
End Sub
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Yes, you code makes sense, but it is not what I am asking....

I am asking why when using iLocation in B4i that Location.Time returns the time of the device and not the time sent from the GPS Location?

I have proven this by setting my device time to 15 mins early (unticking automatic time) and Location.Time returns the same 15 mins early time...

Surely this is a bug?

It should be sending the GPS time from the location detected !

Thanks
 
Upvote 0

emexes

Expert
Licensed User
Surely this is a bug?

It should be sending the GPS time from the location detected !

Maybe Apple's idea of Location.Time is that it is a timestamp of when the reading was done, not of the actual GPS time from the satellites.

Or maybe they're just overcooking (or erring on the side of caution about) user privacy per usual.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
Yes, you code makes sense, but it is not what I am asking....

I am asking why when using iLocation in B4i that Location.Time returns the time of the device and not the time sent from the GPS Location?

I have proven this by setting my device time to 15 mins early (unticking automatic time) and Location.Time returns the same 15 mins early time...

Surely this is a bug?

It should be sending the GPS time from the location detected !

Thanks
What is the output of this: ?
log(Location1.Time)
log(DateTime.Now)
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
This would output the device's time when location last changed and current device time.
It does not relate to gps time. If device time is wrong then both outputs would also be wrong
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
This would output the device's time when location last changed and current device time.
It does not relate to gps time. If device time is wrong then both outputs would also be wrong
This really can't be!
I use this procedure for many years and it works very well, even with all iOS versions.
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Same here. But now I find that I have been misled.
Check it yourself. Download the sample gps code, set your device time to some other time and see what Location.Time reports back. It is certainly not the time sent from the GPS satellite for me....
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Below I have added your code to the sample code for this Library.

I then set my device time to 01.01 (bearing in mine I am in London and it is 14:22 in the afternoon

This is what my iPhone shows.

IMG_0057.PNG



GPS Location Sample Code:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #PlistExtra:<key>NSLocationWhenInUseUsageDescription</key><string>Used to display the current navigation data.</string>
    #PlistExtra:<key>NSLocationUsageDescription</key><string>Used to display the current navigation data.</string>
#End Region


#IgnoreWarnings: 17

'use the distribution certificate
#CertificateFile: ios_distribution.cer

'#Entitlement: <key>aps-environment</key><string>production</string>
#ProvisionFile: Adhoc.mobileprovision

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private LocManager As LocationManager
    Private lblAccuracy As Label
    Private lblAltitude As Label
    Private lblBearing As Label
    Private lblEnable As Label
    Private lblHeading As Label
    Private lblLL As Label
    Private lblSpeed As Label
    Private lblTime As Label
    
    Public gpsTime As Long
    Private GPSTimer As Timer
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.Color = Colors.White
    Page1.RootPanel.LoadLayout("2")
    NavControl.ShowPage(Page1)
    LocManager.Initialize("LocManager")
    
    GPSTimer.Initialize("GPSTimer",1000)
    GPSTimer.Enabled = True
End Sub

Private Sub LocManager_AuthorizationStatusChanged (Status As Int)
    lblEnable.Visible = (LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_DENIED _
        Or LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_RESTRICTED)
    StartLocationUpdates
End Sub

Private Sub StartLocationUpdates
    'if the user allowed us to use the location service or if we never asked the user before then we call LocationManager.Start.
    If LocManager.IsAuthorized Or LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_NOT_DETERMINED Then
        LocManager.Start(0)
    End If
    LocManager.StartHeading
End Sub

Private Sub Application_Foreground
    StartLocationUpdates
End Sub

Private Sub Application_Background
    LocManager.Stop
    LocManager.StopHeading
End Sub

Private Sub LocManager_HeadingChanged (MagneticHeading As Double, TrueHeading As Double)
    If TrueHeading >= 0 Then
        lblHeading.Text = NumberFormat(TrueHeading, 1, 0) & Chr(176) & " (true north)"
    Else
        lblHeading.Text = NumberFormat(MagneticHeading, 1, 0) & Chr(176) & " (magnetic)"
    End If
    
End Sub
Sub LocManager_AllowCalibration As Boolean
    Return
End Sub

Private Sub LocManager_LocationError
    Log("Error: " & LastException.Description)
End Sub

Private Sub LocManager_LocationChanged (Location1 As Location)
    If Location1.VerticalAccuracy >= 0 Then
        lblAltitude.Text =    NumberFormat(Location1.Altitude, 1, 1) & "m"
    Else
        lblAltitude.Text = "N/A"
    End If
    lblBearing.Text = ValueOrNA (Location1.Bearing, 1, Chr(176))
    If Location1.Accuracy >= 0 Then
        lblLL.Text = NumberFormat(Location1.Latitude, 2, 4) & " / " & NumberFormat(Location1.Longitude, 2, 4)
    Else
        lblLL.Text = "N/A"
    End If
    lblSpeed.Text = ValueOrNA(Location1.Speed, 1, "m/s")
    If Location1.Time > 0 Then
        gpsTime = DateTime.Now - Location1.Time
    End If
    lblAccuracy.Text = ValueOrNA(Location1.Accuracy, 2, "m")
End Sub

Private Sub ValueOrNA(value As Double, NumberOfFractions As Int, unit As String) As String
    If value < 0 Then
        Return "N/A"
    Else
        Return NumberFormat(value, 1, NumberOfFractions) & unit
    End If
End Sub

Sub GpsTimer_Tick
    Dim Time As Long
    Time = DateTime.Now - gpsTime
    lblTime.Text = DateTime.Time(Time)
End Sub
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
But did you change the device time and see what happens ?

You only have a difference because it takes 0.026 of a second from when it triggers a location change to when you compare it to device time. Both are still device time.
This is not reporting the correct GPS time from the Location (i.e. it is not coming from the Satellite)

Try it and you will see.

B4A Location.Time is correct and it comes from the Location (i.e. the Satellite)
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
I think you are right.
I set the time according to the radio time and it looks quite different.
 

Attachments

  • 9E3F0DF0-AF57-489F-998A-29076D0B0965.png
    9E3F0DF0-AF57-489F-998A-29076D0B0965.png
    136.5 KB · Views: 83
Upvote 0

Filippo

Expert
Licensed User
Longtime User
I have found something that is relatively old.
This means that it is not a bug, but the iOS procedure.
 
Upvote 0
Top