Dowemo
0 0 0 0


Question:

How can I get the current date time from GPS/glonas/baido satellites on my mobile device with Delphi Android programming?

At this time I can just get longitude and latitude from the location sensor.

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;

I know it's easier to use GSM network for time but there is no mobile network available on my case.

Is this possible at all?


Best Answer:


when you connect location sensor from the provided framware it just provide you location data

but you can get raw data and grab time data

FYI

because the handset companies using chap gps hardware's on their product,the output data have low accuracy

for example data is sampling in 1Hz rate so the best value you get is accuracy 1 second:

use this code:

    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;

this output is like 1505216957000 time stamp , but for low accuracy the last 3 digit is always 0 so you must remove 000 from last of number and then convert it to your time zone




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs