Example usage for android.location Criteria setAltitudeRequired

List of usage examples for android.location Criteria setAltitudeRequired

Introduction

In this page you can find the example usage for android.location Criteria setAltitudeRequired.

Prototype

public void setAltitudeRequired(boolean altitudeRequired) 

Source Link

Document

Indicates whether the provider must provide altitude information.

Usage

From source file:com.fpil.android.remotesensor.MainDisplay.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    Criteria locationCriteria = new Criteria();
    locationCriteria.setAccuracy(Criteria.ACCURACY_FINE);
    locationCriteria.setAltitudeRequired(false);
    locationCriteria.setBearingRequired(false);
    locationCriteria.setCostAllowed(true);
    locationCriteria.setPowerRequirement(Criteria.NO_REQUIREMENT);

    locationProviderName = locationManager.getBestProvider(locationCriteria, true);

    if (ActivityCompat.checkSelfPermission(getActivity(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show();
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        this.startActivity(myIntent);
    }//from w  w w .j av  a2s. c o m

    if (locationProviderName != null && locationManager.isProviderEnabled(locationProviderName)) {
        // Provider is enabled
        Toast.makeText(getActivity(), R.string.gps_available, Toast.LENGTH_LONG).show();
    } else {
        // Provider not enabled, prompt user to enable it
        Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show();
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        this.startActivity(myIntent);
    }
}

From source file:com.zainsoft.ramzantimetable.QiblaActivity.java

private void registerForGPS() {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);/*from   w  w w .j  av a 2 s .c o m*/
    criteria.setSpeedRequired(false);
    criteria.setCostAllowed(true);
    LocationManager locationManager = ((LocationManager) getSystemService(Context.LOCATION_SERVICE));
    String provider = locationManager.getBestProvider(criteria, true);

    if (provider != null) {
        locationManager.requestLocationUpdates(provider, MIN_LOCATION_TIME, MIN_LOCATION_DISTANCE,
                qiblaManager);
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_LOCATION_TIME,
            MIN_LOCATION_DISTANCE, qiblaManager);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_LOCATION_TIME,
            MIN_LOCATION_DISTANCE, qiblaManager);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location == null) {
        location = ((LocationManager) getSystemService(Context.LOCATION_SERVICE))
                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
    }
    if (location != null) {
        qiblaManager.onLocationChanged(location);
    }

}

From source file:com.google.ytd.SubmitActivity.java

private void getVideoLocation() {
    this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_HIGH);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);/*  w  w  w.  j  a v  a  2  s .c om*/
    criteria.setSpeedRequired(false);
    criteria.setCostAllowed(true);

    String provider = locationManager.getBestProvider(criteria, true);

    this.locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                SubmitActivity.this.videoLocation = location;
                double lat = location.getLatitude();
                double lng = location.getLongitude();
                Log.d(LOG_TAG, "lat=" + lat);
                Log.d(LOG_TAG, "lng=" + lng);

                TextView locationText = (TextView) findViewById(R.id.locationLabel);
                locationText.setText("Geo Location: " + String.format("lat=%.2f lng=%.2f", lat, lng));
                locationManager.removeUpdates(this);
            } else {
                Log.d(LOG_TAG, "location is null");
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

    };

    if (provider != null) {
        locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);
    }
}

From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java

/**
 * Get provider name.//from w w  w.  j a  v  a 2 s  . com
 * @return Name of best suiting provider.
 * */
String getProviderName() {
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setPowerRequirement(Criteria.POWER_LOW); // Chose your desired power consumption level.
    criteria.setAccuracy(Criteria.ACCURACY_FINE); // Choose your accuracy requirement.
    criteria.setSpeedRequired(false); // Chose if speed for first location fix is required.
    criteria.setAltitudeRequired(false); // Choose if you use altitude.
    criteria.setBearingRequired(false); // Choose if you use bearing.
    criteria.setCostAllowed(false); // Choose if this provider can waste money :-)

    // Provide your criteria and flag enabledOnly that tells
    // LocationManager only to return active providers.
    return locationManager.getBestProvider(criteria, true);
}

From source file:com.moodmap.HomeActivity.java

private void registerLocationListeners() {
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    if (mLocationListener_Fine == null) {
        mLocationListener_Fine = new LocationListener() {
            // LocationListener
            @Override/*from w w w.ja v a  2 s. co  m*/
            public void onLocationChanged(Location location) {

                float currentLocationAccuracy = location.getAccuracy();

                myLocationFixCnt_Fine++;
                if ((myLocationFixCnt_Fine >= Constants.kMaxGpsFixCnt)
                        || ((location.hasAccuracy()) && (currentLocationAccuracy <= 60.0))) // tighter,
                                                                                                                                                   // slower
                                                                                                                                                   // location
                {
                    // stop the fine location service
                    mLocationManager.removeUpdates(this);

                    // also stop the coarse location updates, if for some
                    // reason it has not resolved yet
                    if (mLocationListener_Coarse != null) {
                        mLocationManager.removeUpdates(mLocationListener_Coarse);
                    }
                }
                updateMyLocation(location);
            }

            @Override
            public void onProviderDisabled(String provider) {
                Log.v(Constants.LOGTAG, "Fine Provider Disabled: " + provider);
            }

            @Override
            public void onProviderEnabled(String provider) {
                Log.v(Constants.LOGTAG, "Fine Provider Enabled: " + provider);
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                myStatusChangeCnt_Fine++;
                if ((status == LocationProvider.OUT_OF_SERVICE))
                // not sure if needed (myStatusChangeCnt_Fine >=
                // Constants.kMaxGpsFixCnt))
                {
                    // if cannot resolve the location, do not leave the gps
                    // running
                    mLocationManager.removeUpdates(mLocationListener_Fine);
                }
                Log.v(Constants.LOGTAG, "Fine Provider Status Change (OVER): " + provider + " status:" + status
                        + " myStatusChangeCnt_Fine:" + myStatusChangeCnt_Fine);

                // LocationProvider.OUT_OF_SERVICE
            }
        };
    }

    if (mLocationListener_Coarse == null) {
        mLocationListener_Coarse = new LocationListener() {
            // LocationListener
            @Override
            public void onLocationChanged(Location location) {

                float currentLocationAccuracy = location.getAccuracy();

                myLocationFixCnt_Coarse++;
                if ((myLocationFixCnt_Coarse >= Constants.kMaxGpsFixCnt)
                        || ((location.hasAccuracy()) && (currentLocationAccuracy <= 1000.0))) // quick,
                                                                                                                                                       // rough
                                                                                                                                                       // location
                {
                    // stop the coarse location service
                    mLocationManager.removeUpdates(this);
                }
                updateMyLocation(location);
            }

            @Override
            public void onProviderDisabled(String provider) {
                Log.v(Constants.LOGTAG, "Provider Disabled: " + provider);
            }

            @Override
            public void onProviderEnabled(String provider) {
                Log.v(Constants.LOGTAG, "Provider Enabled: " + provider);
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                Log.v(Constants.LOGTAG, "Provider Status Change: " + provider + " status:" + status);
                // LocationProvider.OUT_OF_SERVICE
            }
        };
    }

    // still in registerLocationListeners
    //
    String provider = null;
    Criteria crta = new Criteria();
    crta.setAccuracy(Criteria.ACCURACY_FINE);
    crta.setAltitudeRequired(false);
    crta.setBearingRequired(false);
    crta.setCostAllowed(false); // Indicates whether the provider is allowed
                                // to incur monetary cost.
                                // crta.setPowerRequirement(Criteria.POWER_MEDIUM); // POWER_LOW);
    provider = mLocationManager.getBestProvider(crta, true);
    // provider = LocationManager.NETWORK_PROVIDER;

    // get the last, possibly very wrong location
    currentLocation = mLocationManager.getLastKnownLocation(provider);
    // updateMyLocation(location);

    // minTime (2nd) the minimum time interval for notifications, in
    // milliseconds. This field is only used as a hint to conserve power,
    // and actual time between location updates may be greater or lesser
    // than this value.
    // minDistance (3rd)the minimum distance interval for notifications, in
    // meters
    // should be ~ 10000, 100
    // mLocationManager.requestLocationUpdates(provider, 3000, 50,
    // mLocationListener_Fine);
    mLocationManager.requestLocationUpdates(provider, 3000, 0, mLocationListener_Fine);

    // Add second quick location provider
    Criteria coarse = new Criteria();
    coarse.setAccuracy(Criteria.ACCURACY_COARSE);
    coarse.setAltitudeRequired(false);
    coarse.setBearingRequired(false);
    // coarse.setCostAllowed(false);
    // crta.setPowerRequirement(Criteria.POWER_MEDIUM); // POWER_LOW);
    String coarseProvider = mLocationManager.getBestProvider(coarse, true);
    if ((provider != null) && (!provider.contentEquals(coarseProvider))) {
        // only add coarse location resolution if DIFFERENT than the fine
        // location provider
        mLocationManager.requestLocationUpdates(coarseProvider, 1000, 1000, mLocationListener_Coarse);
    }
}

From source file:pandroid.agent.PandroidAgentListener.java

private void gpsLocation() {
    // Starts with GPS, if no GPS then gets network location
    //       /*from   www.ja v a  2  s.  c o  m*/
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = lm.getProviders(true);
    Log.d("PANDROID providers count", "" + providers.size());

    /* Loop over the array backwards, and if you get an accurate location, then break out the loop*/
    Location loc = null;

    for (int i = providers.size() - 1; i >= 0; i--) {
        Log.d("PANDROID providers", providers.get(i));
        loc = lm.getLastKnownLocation(providers.get(i));
        if (loc != null)
            break;
    }

    if (loc != null) {
        Log.d("PANDROID", "loc != null");
        //if(latitude != loc.getLatitude() || longitude != loc.getLongitude()) {
        lastGpsContactDateTime = getHumanDateTime(-1);
        //`}
        Log.d("LATITUDE", Double.valueOf(loc.getLatitude()).toString());
        Log.d("LONGITUDE", Double.valueOf(loc.getLongitude()).toString());
        putSharedData("PANDROID_DATA", "latitude", Double.valueOf(loc.getLatitude()).toString(), "float");
        putSharedData("PANDROID_DATA", "longitude", Double.valueOf(loc.getLongitude()).toString(), "float");
    }
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    String bestProvider = lm.getBestProvider(criteria, true);

    // If not provider found, abort GPS retrieving
    if (bestProvider == null) {
        Log.e("LOCATION", "No location provider found!");
        return;
    }

    lm.requestLocationUpdates(bestProvider, Core.interval, 15, new LocationListener() {
        public void onLocationChanged(Location location) {
            Log.d("Best latitude", Double.valueOf(location.getLatitude()).toString());
            putSharedData("PANDROID_DATA", "latitude", Double.valueOf(location.getLatitude()).toString(),
                    "float");
            Log.d("Best longitude", Double.valueOf(location.getLongitude()).toString());
            putSharedData("PANDROID_DATA", "longitude", Double.valueOf(location.getLongitude()).toString(),
                    "float");
        }

        public void onStatusChanged(String s, int i, Bundle bundle) {

        }

        public void onProviderEnabled(String s) {
            // try switching to a different provider
        }

        public void onProviderDisabled(String s) {
            putSharedData("PANDROID_DATA", "enabled_location_provider", "disabled", "string");
        }
    });
    //}

}

From source file:reportsas.com.formulapp.Formulario.java

public void CapturaL() {
    if (parametroGPS == null) {

        parametroGPS = new ParametrosRespuesta(1);
        manejador = (LocationManager) getSystemService(LOCATION_SERVICE);
        Criteria criterio = new Criteria();
        criterio.setCostAllowed(false);/*from w ww.  ja  va2s.c  om*/
        criterio.setAltitudeRequired(false);
        criterio.setAccuracy(Criteria.ACCURACY_FINE);
        proveedor = manejador.getBestProvider(criterio, true);
        Location localizacion = manejador.getLastKnownLocation(proveedor);
        capturarLocalizacion(localizacion);

    }

    Intent intentoDlgUno = new Intent(this, dialogUbicacion.class);
    intentoDlgUno.putExtra("location", parametroGPS.getValor());
    startActivityForResult(intentoDlgUno, 0);

}

From source file:reportsas.com.formulapp.Formulario.java

public void HabilitarParametros(Menu menu) {
    for (int i = 0; i < encuesta.getParametros().size(); i++) {

        switch (encuesta.getParametros().get(i).getIdParametro()) {
        // Captura GPS
        case 1:/*  w  w  w.j  a  v a  2 s  .  c o m*/

            menu.getItem(2).setVisible(true);
            parametroGPS = new ParametrosRespuesta(1);
            manejador = (LocationManager) getSystemService(LOCATION_SERVICE);
            if (!manejador.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                AlertDialog alert = null;
                final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("El sistema GPS esta desactivado, Debe activarlo!").setCancelable(false)
                        .setPositiveButton("Activar GPS", new DialogInterface.OnClickListener() {
                            public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                                    @SuppressWarnings("unused") final int id) {
                                startActivity(
                                        new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                            }
                        });
                alert = builder.create();
                alert.show();
            }
            Criteria criterio = new Criteria();
            criterio.setCostAllowed(false);
            criterio.setAltitudeRequired(false);
            criterio.setAccuracy(Criteria.ACCURACY_FINE);
            proveedor = manejador.getBestProvider(criterio, true);
            Location localizacion = manejador.getLastKnownLocation(proveedor);
            capturarLocalizacion(localizacion);
            manejador.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this);
            Toast toast1;
            if (parametroGPS.getValor().equals("Posicion Desconocida")) {
                toast1 = Toast.makeText(this, "Posicion Desconocida.", Toast.LENGTH_SHORT);

            } else {
                toast1 = Toast.makeText(this, "Localizacin obtenida exitosamente.", Toast.LENGTH_SHORT);

            }

            toast1.show();
            break;
        // Captura Imgen
        case 2:

            menu.getItem(0).setVisible(true);
            break;
        // Lectura de Codigo
        case 3:

            menu.getItem(1).setVisible(true);
            break;

        default:

            break;
        }

    }

}

From source file:com.BeatYourRecord.SubmitActivity.java

private void getVideoLocation() {
    this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_HIGH);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);/*from w w  w  . jav  a 2  s.c  om*/
    criteria.setSpeedRequired(false);
    criteria.setCostAllowed(true);

    String provider = locationManager.getBestProvider(criteria, true);

    this.locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                SubmitActivity.this.videoLocation = location;
                lat = location.getLatitude();
                lng = location.getLongitude();
                Log.d(LOG_TAG, "lat=" + lat);
                Log.d(LOG_TAG, "lng=" + lng);

                TextView locationText = (TextView) findViewById(R.id.locationLabel);
                locationText.setText("Geo Location: " + String.format("lat=%.2f lng=%.2f", lat, lng));
                locationManager.removeUpdates(this);
            } else {
                Log.d(LOG_TAG, "location is null");
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

    };

    if (provider != null) {
        locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);
    }
}

From source file:com.rareventure.gps2.reviewer.map.OsmMapGpsTrailerReviewerMapActivity.java

public void setupLocationUpdates(GpsLocationOverlay gpsLocationOverlay) {
    //the user may have disabled us from reading location data
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        Criteria criteria = new Criteria();
        criteria.setSpeedRequired(false);
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);/*from ww w .j  a  v a 2s.  com*/

        String locationProviderName = locationManager.getBestProvider(criteria, true);
        locationManager.requestLocationUpdates(locationProviderName, 0, 0, gpsLocationOverlay, getMainLooper());
    }
}