Location getTime - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Location getTime method.

This code example shows how to use the following methods:getTime
		Location loc2 = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);	
		 
		if(loc2 == null) return loc1;
		if(loc1 == null) return loc2;
		 
		if(loc1.getTime() > loc2.getTime()){
			return loc1;
		}else{ 
			return loc2;
		} 
		 
		 
	} 
	 
	private static float distFrom(double lat1, double lng1, double lat2, double lng2) {
	     
		double earthRadius = 3958.75;
		double dLat = Math.toRadians(lat2-lat1);
		double dLng = Math.toRadians(lng2-lng1);
		double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
10
CodeRank
This code example shows how to use the following methods:getTime
    ListenerRegistration(String provider, long minTime, float minDistance, Location locationAtCreation,
               LocationListener listener) {
      this.provider = provider;
      this.minTime = minTime;
      this.minDistance = minDistance;
      this.lastSeenTime = locationAtCreation == null ? 0 : locationAtCreation.getTime();
      this.lastSeenLocation = locationAtCreation;
      this.listener = listener;
    } 
  } 
 
  /** Mapped by provider. */ 
  private final Map<String, List<ListenerRegistration>> locationListeners =
      new HashMap<String, List<ListenerRegistration>>();
 
  @Implementation 
  public boolean isProviderEnabled(String provider) {
    LocationProviderEntry map = providersEnabled.get(provider);
    if (map != null) {
      Boolean isEnabled = map.getKey();
10
CodeRank
This code example shows how to use the following methods:getTime
      return location2;
 
    if (location2 == null)
      return location1;
 
    if (location2.getTime() > location1.getTime())
      return location2;
    else 
      return location1;
  } 
 
  /** 
   * Get the latest location trying multiple providers 
   * <p> 
   * Calling this method requires that your application's manifest contains the 
   * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission 
   * 
   * @param context 
   * @return latest location set or null if none 
   */ 
9
CodeRank
This code example shows how to use the following methods:getTime
		 
		return new ILogPack(Geo.Keys.GPS_COORDS, "[" + loc[0] + "," + loc[1] + "]");
	} 
	 
	public long getTime() { 
		return mLastLocation.getTime();
	} 
	 
	public double[] updateLocation() { 
		 
		if (mLastLocation != null) {
			//Log.d(LOG, "lat/lng: " + l.getLatitude() + ", " + l.getLongitude()); 
			return new double[] {mLastLocation.getLatitude(),mLastLocation.getLongitude()};
		} else { 
			return null; 
		} 
	 
	} 
	 
	public void stopUpdates() { 
8
CodeRank
This code example shows how to use the following methods:getProvider, getTime
    public static Location selectBetterLocation(Location location1, Location location2) {
        if (location1 == null) return location2;
        else if (location2 == null) return location1;
        else { 
            long time1 = location1.getTime();
            long time2 = location2.getTime();
 
            boolean firstFine = isFineLocation(location1);
            boolean secondFine = isFineLocation(location2);
 
            if (firstFine && !secondFine) {
                time1 += FINE_LOCATION_TIME_ADVANTAGE;
            } else if (!firstFine && secondFine) {
                time2 += FINE_LOCATION_TIME_ADVANTAGE;
            } 
 
            if (time1 > time2) return location1;
            else return location2;
        } 
    } 

7
CodeRank
This code example shows how to use the following methods:getAccuracy, getProvider, getTime
			// 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 

7
CodeRank
This code example shows how to use the following methods:getTime
	private Date _dateTime;
	 
	public LocationIdentifier(Location location)
	{ 
		_location = location;
		_dateTime = new Date(location.getTime()); 
	} 
 
	public void CalculateSpeed(LocationIdentifier previousLocation)
	{ 
		if(_location.hasSpeed())
			_speed = _location.getSpeed();
		else 
		{ 
			double diff = (double)(getDateTime().getTime() - previousLocation.getDateTime().getTime());
			double distance = _location.distanceTo(previousLocation.getLocation());
			_speed = (float) (distance/diff * 3600.0) ;
		} 
		 
	} 
8
CodeRank
This code example shows how to use the following methods:getAccuracy, getLatitude, getLongitude, getProvider, getTime
 
	@Override 
	public void onLocationChanged(Location location) {
		if (isBetterLocation(location, currentLocation)) {
			currentLocation = new Location(location);
			String my_text = String.valueOf(location.getLatitude()) + " / " + String.valueOf(location.getLongitude());
			Log.d(TAG, "Got location: " + my_text);
		} 
	} 
 
	@Override 
	public void onProviderDisabled(String provider) {
		Toast.makeText(appContext, "Disabled provider " + provider, Toast.LENGTH_SHORT).show();
	} 
 
	@Override 
	public void onProviderEnabled(String provider) {
		Toast.makeText(appContext, "Enabled new provider " + provider, Toast.LENGTH_SHORT).show();
	} 
 

6
CodeRank
This code example shows how to use the following methods:getAccuracy, getLatitude, getLongitude, getProvider, getTime
        if ( currentBestLocation == null ) {
            // A new location is always better than no location 
            return true; 
        } 
 
        if ( location.getLatitude() == currentBestLocation.getLatitude()
                && location.getLongitude() == currentBestLocation.getLongitude() ) {
            // No change in location is not better 
            return false; 
        } 
 
        // 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 ) {

6
CodeRank
This code example shows how to use the following methods:getAccuracy, getProvider, getTime
	        // 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 

7
CodeRank

Related Location getTime Questions & Answers:

getTime Method Overview
Return the UTC time of this fix, in milliseconds since January 1, 1970.
See Code Examples for other Android Location Methods: