Location getProvider - 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 getProvider method.

This code example shows how to use the following methods:getProvider, getTime
	private boolean isBetter(Location loc){
		 
		if(result == null) return true; 
		 
		// if this loc is network and there's already an recent async gps update 
		if(result.getTime() > initTime && result.getProvider().equals(LocationManager.GPS_PROVIDER) && loc.getProvider().equals(LocationManager.NETWORK_PROVIDER)){
			AQUtility.debug("inferior location"); 
			return false; 
		} 
		 
		return true; 
		 
		 
	} 
	 
	private void failure(){ 
		 
		if(gpsListener == null && networkListener == null) return;
		 
		AQUtility.debug("fail"); 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLatitude, getLongitude, getProvider
     
    class DemoLocationListener implements LocationListener {
 
		@Override 
		public void onLocationChanged(Location location) {
			if (location.getProvider() == LocationManager.GPS_PROVIDER) {
				 
			} 
			StringBuffer locationInfo = new StringBuffer();
			locationInfo.append("Lat : " + new DecimalFormat("#.#####").format(location.getLatitude()) + "\n");
			locationInfo.append("Lon: "  + new DecimalFormat("#.#####").format(location.getLongitude()) + "\n");
			 
			info.setText(locationInfo.toString());
			 
		} 
 
		@Override 
		public void onProviderDisabled(String provider) {			
		} 
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:distanceTo, getAccuracy, getLatitude, getLongitude, getProvider
      Log.wtf(getClass().getSimpleName(),
              "Got null for getBestLocation()"); 
    } 
    else { 
      Log.i(getClass().getSimpleName(),
            String.format("%s %f:%f (%f meters)", loc.getProvider(),
                          loc.getLatitude(), loc.getLongitude(),
                          loc.getAccuracy()));
    } 
  } 
 
  private Location getBestLocation() {
    Location gps=mgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    Location network=
        mgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
 
    // start off by handling cases where we only have one 
 
    if (gps == null) {
      return(network);

9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProvider
        return provider1.equals(provider2);
    } 
 
    public boolean hasGPSFix() { 
        return (lastLocation != null) &&
            LocationManager.GPS_PROVIDER.equals(lastLocation.getProvider());
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getAccuracy, getLatitude, getLongitude, getProvider, getTime
     * LocationListener overrides below  
     **********************************************************************/ 
    public void onLocationChanged(Location location) {
    	long currentT = 0;
        // we got new location info. 
    	currentT = location.getTime();
    	 
    	if (lastT != 0) {
    		deltaT = currentT - lastT;
    	 
    		// Calculate greater delta T 
    		if ((deltaT > greaterDeltaT) && (deltaT != currentT)) {
    			greaterDeltaT = deltaT;
    		} 
    	} 
    	 
    	//  lets display it in the textview 
        String s = "";
        s += "Time     : "   + currentT + "\n";
        s += "Delta   T: "   + deltaT + "\n";

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Location getProvider Questions & Answers:

getProvider Method Overview
Returns the name of the provider that generated this fix.
See Code Examples for other Android Location Methods: