deuxdeux
deuxdeux

Reputation: 63

Fused Location Api Get time from GPS

I have an application that tracks users location. My application uses FusedLocationApi , Google new way of getting device location using Google Play Services.

Provider of locations that i give from GPS is labeled as fused.

Because of application users may change device time, it is important to get real time from GPS.

Problem is that when i try to get time from Location object , it returns device time not GPS time.

Any solutions to get GPS time in this situation are appreciated.

private Location mLastLocation;    

public void onConnected(Bundle arg0) {

    LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);
}

public void onLocationChanged(Location location) {

    mLastLocation = LocationServices.FusedLocationApi
            .getLastLocation(mGoogleApiClient);

    if (mLastLocation != null) {

        double latitude = mLastLocation.getLatitude();
        double longitude = mLastLocation.getLongitude();
        Date date = new Date(mLastLocation.getTime());

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");            
        String time = dateFormat.format(date)
}

Upvotes: 1

Views: 1618

Answers (1)

theWalker
theWalker

Reputation: 2020

To get GPS UTC, do it in normal way:

LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
// not LocationManager.NETWORK_PROVIDER

@Override
public void onLocationChanged(Location location) 
{   
    long utc = location.getTime();
    // ....
}

Upvotes: 1

Related Questions