1

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

此时我只能从位置传感器获取经度和纬度。

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
  const OldLocation, NewLocation: TLocationCoord2D);
var
  LDecSeparator: String;
begin
  LDecSeparator := FormatSettings.DecimalSeparator;
  FormatSettings.DecimalSeparator := '.';
  // Show current location
  ListBoxItemLatitude.ItemData.Detail  := Format('%2.6f', [NewLocation.Latitude]);
  ListBoxItemLongitude.ItemData.Detail := Format('%2.6f', [NewLocation.Longitude]);
end;

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

这可能吗?

4

2 回答 2

1

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

于 2018-04-15T12:16:50.073 回答
1

当您从提供的框架连接位置传感器时,它只会为您提供位置数据

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

供参考

由于手机公司在其产品上使用了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从最后一个数字中删除,然后将其转换为您的时区

于 2017-09-13T04:36:00.007 回答