0

How to get GPS time or network time, location.getTime() is returning the wrong device date and time. I've tried some tips on web but no answers yet.

Here's what I have now

locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
    location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);


    if (location != null) {
        latitude = location.getLatitude();
        longitude = location.getLongitude();
        datetime = location.getTime();    // the return time is from the device time.... not from the gps

        Log.d("lat",""+location.getLatitude());
        Log.d("long",""+location.getLongitude());
    }
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
Dodong
  • 39
  • 1
  • 7
  • Please show the relevant code `location.getTime()` doesn't say much about which library you are using. And give an example of what you get and what you expected. – Barns May 22 '18 at 00:29

1 Answers1

0

You might be looking for this. You can just get the time of the device when the location was recorded.

Maxime Claude
  • 965
  • 12
  • 27
  • i dont want to get the device time because the user could change it . the answer in the link you posted was returning the device time. – Dodong May 22 '18 at 00:54
  • Yep he could change it. But usually I convert it into UTC before saving it into a server online. On the other hand, depending on where your users live (in non third world countries with internet problems) the phone's time is synchronized with the carrier's time. So converting it into UTC would work because the location time is in UTC. Another thing you could do is to take the phone time only and only when the location's time is correct according tk ykur wishes. – Maxime Claude May 22 '18 at 04:12