如何从FireMonkey for Android中的GPS传感器获取当前日期和时间?

时间:2017-09-12 19:51:20

标签: android delphi firemonkey delphi-10.2-tokyo

如何通过Delphi Android编程在我的移动设备上获取GPS / glonas / baido卫星的当前日期时间?

此时我可以从位置传感器获得经度和纬度。

CButton

我知道使用GSM网络的时间比较容易,但我的情况下没有可用的移动网络。

这有可能吗?

2 个答案:

答案 0 :(得分:1)

当您从提供的framware连接位置传感器时,它只提供位置数据

但您可以获取原始数据并获取时间数据

FYI

因为手机公司在其产品上使用了chap gps硬件,输出数据的准确度较低

例如,数据以1Hz的速率采样,因此您获得的最佳值是精确度1秒:

使用此代码:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      LocationManagerService: JObject;
      location : JLocation;
    begin
      if not Assigned(FLocationManager) then
      begin
        LocationManagerService := SharedActivityContext.getSystemService(TJContext.JavaClass.LOCATION_SERVICE);
        FLocationManager := TJLocationManager.Wrap((LocationManagerService as ILocalObject).GetObjectID);
        if not Assigned(locationListener) then
          locationListener := TLocationListener.Create(self);
        FLocationManager.requestLocationUpdates(TJLocationManager.JavaClass.GPS_PROVIDER, 10000, 10, locationListener,
            TJLooper.JavaClass.getMainLooper);
      end;                      

      location := FLocationManager.getLastKnownLocation(TJLocationManager.JavaClass.GPS_PROVIDER);
  Memo1.Lines.Add(location.getTime.ToString);
    end;

此输出类似于1505216957000时间戳,但由于精度较低,最后3位数始终为0,因此您必须从最后一位数字中删除000,然后将其转换为您的时区

答案 1 :(得分:1)

这不是GPS网络时间。它是GPS接收器的最后一个有效位置 FIX ,可能是不久前的。

相关问题