Java Code Examples for android.location.Location#getTime()

The following examples show how to use android.location.Location#getTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MeasurementParser.java    From TowerCollector with Mozilla Public License 2.0 6 votes vote down vote up
protected void fixMeasurementTimestamp(Measurement measurement, Location location) {
    // update timestamp if user has incorrect system time in phone
    // that means if earlier than fix or later by one day
    // but only if gps time later than app build time
    long systemTimestamp = measurement.getMeasuredAt();
    long gpsTimestamp = location.getTime();
    if (!systemTimeValidator.isValid(systemTimestamp, gpsTimestamp)) {
        long appBuildTimestamp = BuildConfig.BUILD_DATE_TIME;
        Timber.i("fixMeasurementTimestamp(): Fixing measurement time = %s, gps time = %s, app time = %s", systemTimestamp, gpsTimestamp, appBuildTimestamp);
        // starting on November 3, 2019, mobile devices manufactured between 2006 and 2016 may have their GPS accuracy impacted due to GPS Rollover issue
        if (gpsTimestamp >= appBuildTimestamp) {
            measurement.setMeasuredAt(gpsTimestamp);
            Timber.i("fixMeasurementTimestamp(): Fixed measurement time using gps time");
        } else if (systemTimestamp < appBuildTimestamp) {
            throw new IllegalStateException("System (" + systemTimestamp + ") and GPS (" + gpsTimestamp + ") timestamps are older than app build time (" + appBuildTimestamp + ")");
        }
    }
}
 
Example 2
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Encodes location into ascii encoding.
 */
@Nullable
@VisibleForTesting
static String encodeAsciiLocation(@Nullable Location location) {
    if (location == null) return null;

    // Timestamp in microseconds since the UNIX epoch.
    long timestamp = location.getTime() * 1000;
    // Latitude times 1e7.
    int latitudeE7 = (int) (location.getLatitude() * 10000000);
    // Longitude times 1e7.
    int longitudeE7 = (int) (location.getLongitude() * 10000000);
    // Radius of 68% accuracy in mm.
    int radius = (int) (location.getAccuracy() * 1000);

    // Encode location using ascii protobuf format followed by base64 encoding.
    // https://goto.google.com/partner_location_proto
    String locationAscii = String.format(Locale.US,
            "role:1 producer:12 timestamp:%d latlng{latitude_e7:%d longitude_e7:%d}"
                    + " radius:%d",
            timestamp, latitudeE7, longitudeE7, radius);
    return new String(Base64.encode(locationAscii.getBytes(), Base64.NO_WRAP));
}
 
Example 3
Source File: BackendHelper.java    From android_packages_apps_UnifiedNlp with Apache License 2.0 6 votes vote down vote up
private void setLastLocation(Location location) {
    if (location == null || !location.hasAccuracy()) {
        return;
    }
    if (location.getExtras() == null) {
        location.setExtras(new Bundle());
    }
    location.getExtras().putString(LOCATION_EXTRA_BACKEND_PROVIDER, location.getProvider());
    location.getExtras().putString(LOCATION_EXTRA_BACKEND_COMPONENT,
            serviceIntent.getComponent().flattenToShortString());
    location.setProvider("network");
    if (!location.hasAccuracy()) {
        location.setAccuracy(50000);
    }
    if (location.getTime() <= 0) {
        location.setTime(System.currentTimeMillis());
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        updateElapsedRealtimeNanos(location);
    }
    Location noGpsLocation = new Location(location);
    noGpsLocation.setExtras(null);
    location.getExtras().putParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION, noGpsLocation);
    lastLocation = location;
}
 
Example 4
Source File: Kalman.java    From DejaVu with GNU General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param location
 */

public Kalman(Location location, double coordinateNoise) {
    final double accuracy = location.getAccuracy();
    final double coordinateNoiseDegrees = coordinateNoise * BackendService.METER_TO_DEG;
    double position, noise;
    long timeMs = location.getTime();

    // Latitude
    position = location.getLatitude();
    noise = accuracy * BackendService.METER_TO_DEG;
    mLatTracker = new Kalman1Dim(coordinateNoiseDegrees, timeMs);
    mLatTracker.setState(position, 0.0, noise);

    // Longitude
    position = location.getLongitude();
    noise = accuracy * Math.cos(Math.toRadians(location.getLatitude())) * BackendService.METER_TO_DEG;
    mLonTracker = new Kalman1Dim(coordinateNoiseDegrees, timeMs);
    mLonTracker.setState(position, 0.0, noise);

    // Altitude
    if (location.hasAltitude()) {
        position = location.getAltitude();
        noise = accuracy;
        mAltTracker = new Kalman1Dim(ALTITUDE_NOISE, timeMs);
        mAltTracker.setState(position, 0.0, noise);
    }
    mTimeOfUpdate = timeMs;
    samples = 1;
}
 
Example 5
Source File: GearService.java    From WheelLogAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void onLocationChanged(Location location) {
        if(bHasSpeed = location.hasSpeed())
            mSpeed = location.getSpeed();
        if(bHasAltitude = location.hasAltitude())
            mAltitude = location.getAltitude();
        if(location.hasSpeed())
            mSpeed = location.getSpeed();
        if(bHasBearing = location.hasBearing())
            mBearing = location.getBearing();
        mLatitude = location.getLatitude();
        mLongitude = location.getLongitude();
        mTime = location.getTime();
//        transmitMessage(); Me lo he llevado a la rutina que se ejecuta de forma temporizada
    }
 
Example 6
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Encodes location into proto encoding.
 */
@Nullable
@VisibleForTesting
static String encodeProtoLocation(@Nullable Location location) {
    if (location == null) return null;

    // Timestamp in microseconds since the UNIX epoch.
    long timestamp = location.getTime() * 1000;
    // Latitude times 1e7.
    int latitudeE7 = (int) (location.getLatitude() * 10000000);
    // Longitude times 1e7.
    int longitudeE7 = (int) (location.getLongitude() * 10000000);
    // Radius of 68% accuracy in mm.
    int radius = (int) (location.getAccuracy() * 1000);

    // Create a LatLng for the coordinates.
    PartnerLocationDescriptor.LatLng latlng = new PartnerLocationDescriptor.LatLng();
    latlng.latitudeE7 = latitudeE7;
    latlng.longitudeE7 = longitudeE7;

    // Populate a LocationDescriptor with the LatLng.
    PartnerLocationDescriptor.LocationDescriptor locationDescriptor =
            new PartnerLocationDescriptor.LocationDescriptor();
    locationDescriptor.latlng = latlng;
    // Include role, producer, timestamp and radius.
    locationDescriptor.role = PartnerLocationDescriptor.CURRENT_LOCATION;
    locationDescriptor.producer = PartnerLocationDescriptor.DEVICE_LOCATION;
    locationDescriptor.timestamp = timestamp;
    locationDescriptor.radius = (float) radius;
    return encodeLocationDescriptor(locationDescriptor);
}
 
Example 7
Source File: OrientationManager.java    From PTVGlass with MIT License 5 votes vote down vote up
/**
 * Starts tracking the user's location and orientation. After calling this method, any
 * {@link OnChangedListener}s added to this object will be notified of these events.
 */
public void start() {
    if (!mTracking) {
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),
                SensorManager.SENSOR_DELAY_UI);

        // The rotation vector sensor doesn't give us accuracy updates, so we observe the
        // magnetic field sensor solely for those.
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                SensorManager.SENSOR_DELAY_UI);

        Location lastLocation = mLocationManager
                .getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
        if (lastLocation != null) {
            long locationAge = lastLocation.getTime() - System.currentTimeMillis();
            if (locationAge < MAX_LOCATION_AGE_MILLIS) {
                mLocation = lastLocation;
                updateGeomagneticField();
            }
        }

        if (mLocationProvider != null) {
            mLocationManager.requestLocationUpdates(mLocationProvider,
                    MILLIS_BETWEEN_LOCATIONS, METERS_BETWEEN_LOCATIONS, mLocationListener,
                    Looper.getMainLooper());
        }

        mTracking = true;
    }
}
 
Example 8
Source File: OrientationManager.java    From PTVGlass with MIT License 5 votes vote down vote up
/**
 * Starts tracking the user's location and orientation. After calling this method, any
 * {@link OnChangedListener}s added to this object will be notified of these events.
 */
public void start() {
    if (!mTracking) {
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),
                SensorManager.SENSOR_DELAY_UI);

        // The rotation vector sensor doesn't give us accuracy updates, so we observe the
        // magnetic field sensor solely for those.
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                SensorManager.SENSOR_DELAY_UI);

        Location lastLocation = mLocationManager
                .getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
        if (lastLocation != null) {
            long locationAge = lastLocation.getTime() - System.currentTimeMillis();
            if (locationAge < MAX_LOCATION_AGE_MILLIS) {
                mLocation = lastLocation;
                updateGeomagneticField();
            }
        }

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setBearingRequired(false);
        criteria.setSpeedRequired(false);

        List<String> providers =
                mLocationManager.getProviders(criteria, true /* enabledOnly */);
        for (String provider : providers) {
            mLocationManager.requestLocationUpdates(provider,
                    MILLIS_BETWEEN_LOCATIONS, METERS_BETWEEN_LOCATIONS, mLocationListener,
                    Looper.getMainLooper());
        }

        mTracking = true;
    }
}
 
Example 9
Source File: LocationManager.java    From background-geolocation-android with Apache License 2.0 5 votes vote down vote up
/**
 * Get current location without permission checking
 *
 * @param timeout
 * @param maximumAge
 * @param enableHighAccuracy
 * @return
 * @throws InterruptedException
 * @throws TimeoutException
 */
@SuppressLint("MissingPermission")
public Location getCurrentLocationNoCheck(int timeout, long maximumAge, boolean enableHighAccuracy) throws InterruptedException, TimeoutException {
    final long minLocationTime = System.currentTimeMillis() - maximumAge;
    final android.location.LocationManager locationManager = (android.location.LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);

    Location lastKnownGPSLocation = locationManager.getLastKnownLocation(android.location.LocationManager.GPS_PROVIDER);
    if (lastKnownGPSLocation != null && lastKnownGPSLocation.getTime() >= minLocationTime) {
        return lastKnownGPSLocation;
    }

    Location lastKnownNetworkLocation = locationManager.getLastKnownLocation(android.location.LocationManager.NETWORK_PROVIDER);
    if (lastKnownNetworkLocation != null && lastKnownNetworkLocation.getTime() >= minLocationTime) {
        return lastKnownNetworkLocation;
    }

    Criteria criteria = new Criteria();
    criteria.setAccuracy(enableHighAccuracy ? Criteria.ACCURACY_FINE : Criteria.ACCURACY_COARSE);

    CurrentLocationListener locationListener = new CurrentLocationListener();
    locationManager.requestSingleUpdate(criteria, locationListener, Looper.getMainLooper());

    if (!locationListener.mCountDownLatch.await(timeout, TimeUnit.MILLISECONDS)) {
        locationManager.removeUpdates(locationListener);
        throw new TimeoutException();
    }

    if (locationListener.mLocation != null) {
        return locationListener.mLocation;
    }

    return null;
}
 
Example 10
Source File: BackendService.java    From AppleWifiNlpBackend with Apache License 2.0 5 votes vote down vote up
private synchronized Location calculate(Set<WiFi> wiFis) {
    if (!isConnected()) {
        return null;
    }
    Set<Location> locations = new HashSet<>();
    Set<String> unknown = new HashSet<>();
    for (WiFi wifi : wiFis) {
        Location location = database.get(wifi.getBssid());
        if (location != null) {
            if ((location.getTime() + THIRTY_DAYS) < System.currentTimeMillis()) {
                // Location is old, let's refresh it :)
                unknown.add(wifi.getBssid());
            }
            location.getExtras().putInt(LocationRetriever.EXTRA_SIGNAL_LEVEL, wifi.getRssi());
            if (location.hasAccuracy() && location.getAccuracy() != -1) {
                locations.add(location);
            }
        } else {
            unknown.add(wifi.getBssid());
        }
    }
    Log.d(TAG, "Found " + wiFis.size() + " wifis, of whom " + locations.size() + " with " +
            "location and " + unknown.size() + " unknown.");
    if (!unknown.isEmpty()) {
        if (toRetrieve == null) {
            toRetrieve = unknown;
        } else {
            toRetrieve.addAll(unknown);
        }
    }
    if (thread == null) {
        thread = new Thread(retrieveAction);
        thread.start();
    }
    return calculator.calculate(locations);
}
 
Example 11
Source File: LocationMonitor.java    From ploggy with GNU General Public License v3.0 4 votes vote down vote up
private boolean isBetterLocation(Location location, Location currentBestLocation) {

        final int TWO_MINUTES = 1000 * 60 * 2;

        if (currentBestLocation == null) {
            // A new location is always better than no location
            return true;
        }

        // Check whether the new location fix is newer or older
        long timeDelta = location.getTime() - currentBestLocation.getTime();
        boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
        boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
        boolean isNewer = timeDelta > 0;

        // If it's been more than two minutes since the current location, use the new location
        // because the user has likely moved
        if (isSignificantlyNewer) {
            return true;
        // If the new location is more than two minutes older, it must be worse
        } else if (isSignificantlyOlder) {
            return false;
        }

        // Check whether the new location fix is more or less accurate
        int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
        boolean isLessAccurate = accuracyDelta > 0;
        boolean isMoreAccurate = accuracyDelta < 0;
        boolean isSignificantlyLessAccurate = accuracyDelta > 200;

        // Check if the old and new location are from the same provider
        boolean isFromSameProvider = isSameProvider(location.getProvider(),
                currentBestLocation.getProvider());

        // Determine location quality using a combination of timeliness and accuracy
        if (isMoreAccurate) {
            return true;
        } else if (isNewer && !isLessAccurate) {
            return true;
        } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
            return true;
        }
        return false;
    }
 
Example 12
Source File: DeviceLocation.java    From ARCore-Location with MIT License 4 votes vote down vote up
/**
 * Only replaces current location if this reading is
 * more likely to be accurate
 * @param location
 * @return
 */
protected boolean isBetterLocation(Location location) {
    if (currentBestLocation == null) {
        // A new location is always better than no location
        return true;
    }

    // Check whether the new location fix is newer or older
    long timeDelta = location.getTime() - currentBestLocation.getTime();
    boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
    boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
    boolean isNewer = timeDelta > 0;

    // If it's been more than two minutes since the current location, use the new location
    // because the user has likely moved
    if (isSignificantlyNewer) {
        return true;
        // If the new location is more than two minutes older, it must be worse
    } else if (isSignificantlyOlder) {
        return false;
    }

    // Check whether the new location fix is more or less accurate
    int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
    boolean isLessAccurate = accuracyDelta > 0;
    boolean isMoreAccurate = accuracyDelta < 0;
    boolean isSignificantlyLessAccurate = accuracyDelta > 200;

    // Check if the old and new location are from the same provider
    boolean isFromSameProvider = isSameProvider(location.getProvider(),
            currentBestLocation.getProvider());

    // Determine location quality using a combination of timeliness and accuracy
    if (isMoreAccurate) {
        return true;
    } else if (isNewer && !isLessAccurate) {
        return true;
    } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
        return true;
    }
    return false;
}
 
Example 13
Source File: LocationsMatcher.java    From mytracks with Apache License 2.0 4 votes vote down vote up
private boolean matchLocation(Location location1, Location location2) {
  return (location1.getTime() == location2.getTime())
      && (location1.getLatitude() == location2.getLatitude())
      && (location1.getLongitude() == location2.getLongitude())
      && (location1.getAltitude() == location2.getAltitude());
}
 
Example 14
Source File: Utils.java    From mapbox-events-android with MIT License 4 votes vote down vote up
/**
 * Determines whether one Location reading is better than the current Location fix
 * <p>
 * (c) https://developer.android.com/guide/topics/location/strategies
 *
 * @param location            The new Location that you want to evaluate
 * @param currentBestLocation The current Location fix, to which you want to compare the new one
 */
static boolean isBetterLocation(Location location, Location currentBestLocation) {
  if (currentBestLocation == null) {
    // A new location is always better than no location
    return true;
  }

  // Check whether the new location fix is newer or older
  long timeDelta = location.getTime() - currentBestLocation.getTime();
  boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
  boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
  boolean isNewer = timeDelta > 0;

  // If it's been more than two minutes since the current location, use the new location
  // because the user has likely moved
  if (isSignificantlyNewer) {
    return true;
    // If the new location is more than two minutes older, it must be worse
  } else if (isSignificantlyOlder) {
    return false;
  }

  // Check whether the new location fix is more or less accurate
  int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
  boolean isLessAccurate = accuracyDelta > 0;
  boolean isMoreAccurate = accuracyDelta < 0;
  boolean isSignificantlyLessAccurate = accuracyDelta > ACCURACY_THRESHOLD_METERS;

  // Check if the old and new location are from the same provider
  boolean isFromSameProvider = isSameProvider(location.getProvider(),
          currentBestLocation.getProvider());

  // Determine location quality using a combination of timeliness and accuracy
  if (isMoreAccurate) {
    return true;
  } else if (isNewer && !isLessAccurate) {
    return true;
  } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
    return true;
  }
  return false;
}
 
Example 15
Source File: LocationGPS.java    From VIA-AI with MIT License 4 votes vote down vote up
protected boolean isBetterLocation(Location location, Location currentBestLocation) {
    if (currentBestLocation == null) {
        // A new location is always better than no location
        return true;
    }

    // Check whether the new location fix is newer or older
    long timeDelta = location.getTime() - currentBestLocation.getTime();
    boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
    boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
    boolean isNewer = timeDelta > 0;

    // If it's been more than two minutes since the current location, use the new location
    // because the user has likely moved
    if (isSignificantlyNewer) {
        return true;
        // If the new location is more than two minutes older, it must be worse
    } else if (isSignificantlyOlder) {
        return false;
    }

    // Check whether the new location fix is more or less accurate
    int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
    boolean isLessAccurate = accuracyDelta > 0;
    boolean isMoreAccurate = accuracyDelta < 0;
    boolean isSignificantlyLessAccurate = accuracyDelta > 200;

    // Check if the old and new location are from the same provider
    boolean isFromSameProvider = isSameProvider(location.getProvider(),
            currentBestLocation.getProvider());

    // Determine location quality using a combination of timeliness and accuracy
    if (isMoreAccurate) {
        return true;
    } else if (isNewer && !isLessAccurate) {
        return true;
    } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
        return true;
    }
    return false;
}
 
Example 16
Source File: HistoryRecord.java    From itag with GNU General Public License v3.0 4 votes vote down vote up
private HistoryRecord(String addr, Location location) {
    this.addr = addr;
    this.latitude = location.getLatitude();
    this.longitude = location.getLongitude();
    this.ts = location.getTime();
}
 
Example 17
Source File: LocationGetLocationActivity.java    From coursera-android with MIT License 4 votes vote down vote up
private boolean LastLocationIsAccurate(Location location) {
    return (null != location && location.getAccuracy() <= LocationGetLocationActivity.MIN_LAST_READ_ACCURACY && ((System.currentTimeMillis() - location.getTime()) < LocationGetLocationActivity.FIVE_MIN));
}
 
Example 18
Source File: GpsEventSource.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Determines whether one Location reading is better than the current Location fix
 *
 * @param location
 *         The new Location that you want to evaluate
 * @param currentBestLocation
 *         The current Location fix, to which you want to compare the new one
 */
protected boolean isBetterLocation(
        Location location,
        Location currentBestLocation)
{
    if (currentBestLocation == null) {
        // A new location is always better than no location
        return true;
    }

    // Check whether the new location fix is newer or older
    long timeDelta = location.getTime() - currentBestLocation.getTime();
    boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
    boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
    boolean isNewer = timeDelta > 0;

    // If it's been more than two minutes since the current location, use the new location
    // because the user has likely moved
    if (isSignificantlyNewer) {
        return true;
        // If the new location is more than two minutes older, it must be worse
    } else if (isSignificantlyOlder) {
        return false;
    }

    // Check whether the new location fix is more or less accurate
    int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
    boolean isLessAccurate = accuracyDelta > 0;
    boolean isMoreAccurate = accuracyDelta < 0;
    boolean isSignificantlyLessAccurate = accuracyDelta > 200;

    // Check if the old and new location are from the same provider
    boolean isFromSameProvider =
            isSameProvider(location.getProvider(), currentBestLocation.getProvider());

    // Determine location quality using a combination of timeliness and accuracy
    if (isMoreAccurate) {
        return true;
    } else if (isNewer && !isLessAccurate) {
        return true;
    } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
        return true;
    }
    return false;
}
 
Example 19
Source File: LegacyRequestMapper.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static boolean checkForCompleteGpsData(Location location) {
    return location != null && location.getProvider() != null && location.getTime() != 0;
}
 
Example 20
Source File: AppLocationService.java    From GooglePlayServiceLocationSupport with Apache License 2.0 4 votes vote down vote up
@Override
public Location requestForCurrentLocation() {
    // If Google Play Services is available
    Location currentLocation = null;
    if (servicesConnected()) {
        // Get the current location
        currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    }
    if (currentLocation == null) {

        if (!(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
            Location locationGPS = mLocationService.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            Location locationNet = mLocationService.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            long GPSLocationTime = 0;
            if (null != locationGPS) {
                GPSLocationTime = locationGPS.getTime();
            }

            long NetLocationTime = 0;

            if (null != locationNet) {
                NetLocationTime = locationNet.getTime();
            }

            if (0 < GPSLocationTime - NetLocationTime) {
                currentLocation = locationGPS;
            } else {
                currentLocation = locationNet;
            }
        }else if (!(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED))
            currentLocation = mLocationService.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        else if (!(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED))
            currentLocation = mLocationService.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }
    if (currentLocation != null)
        myCurrentLocation(currentLocation);
    return currentLocation;
}