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:Main.java

/**
 * this criteria will settle for less accuracy, high power, and cost
 *///w w  w . j  a v  a 2 s .  c  o m
public static Criteria createCoarseCriteria() {

    Criteria c = new Criteria();
    c.setAccuracy(Criteria.ACCURACY_COARSE);
    c.setAltitudeRequired(false);
    c.setBearingRequired(false);
    c.setSpeedRequired(false);
    c.setCostAllowed(true);
    c.setPowerRequirement(Criteria.POWER_HIGH);
    return c;

}

From source file:Main.java

public static String getBestProvider(LocationManager locationmanager) {
    String s = null;/*w w  w .  j a  v  a 2 s. co m*/
    if (locationmanager != null) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(2);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(0);
        s = locationmanager.getBestProvider(criteria, true);
        if (s == null)
            s = "network";
    }
    return s;
}

From source file:Main.java

public static String getGpsString(Context context) {
    if (context == null) {
        return null;
    }// w ww . j  ava  2s .c om

    String gps = null;

    Location location = null;
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);

    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    String provider = locationManager.getBestProvider(criteria, true);
    if (provider != null) {
        location = locationManager.getLastKnownLocation(provider);
    }
    if (location != null) {
        double longtitude = location.getLongitude();
        double latitude = location.getLatitude();
        gps = "Lon:" + longtitude + "; Lat:" + latitude;
    }

    if (gps == null) {
        gps = "Lon:0; Lat:0";
    }
    return gps;
}

From source file:com.appdynamics.demo.gasp.utils.LocationServices.java

/**
 * Set Location Services and get current location
 *///from w w  w  .  j  a va  2  s.c o m
public static Location getLocation(Context context) {
    Location location = null;
    try {
        String svcName = Context.LOCATION_SERVICE;
        LocationManager locationManager = (LocationManager) context.getSystemService(svcName);

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setSpeedRequired(false);
        criteria.setCostAllowed(true);
        String provider = locationManager.getBestProvider(criteria, true);
        location = locationManager.getLastKnownLocation(provider);

        Log.i(TAG, "Current Latitude = " + location.getLatitude());
        Log.i(TAG, "Current Longitude = " + location.getLongitude());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return location;
}

From source file:com.ushahidi.android.app.util.Util.java

/** this criteria needs high accuracy, high power, and cost */
public static Criteria createFineCriteria() {

    Criteria c = new Criteria();
    c.setAccuracy(Criteria.ACCURACY_FINE);
    c.setAltitudeRequired(false);//from  w  w  w .  ja  v  a2s  .c o m
    c.setBearingRequired(false);
    c.setSpeedRequired(false);
    c.setCostAllowed(true);
    c.setPowerRequirement(Criteria.POWER_HIGH);
    return c;

}

From source file:com.airbop.library.simple.CommonUtilities.java

/**
 * Simple helper that gets the location criteria that we want. 
 * @return//from  ww  w .jav  a  2 s  .  c om
 */
public static Criteria getCriteria() {
    if (true) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setSpeedRequired(false);
        criteria.setCostAllowed(true);

        return criteria;
    }
    return null;
}

From source file:net.quranquiz.ui.QQMap.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);/*from  ww w. j  a va2s.com*/
    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    map.setOnMarkerClickListener((OnMarkerClickListener) this);

    cairo = new LatLng(30.1, 31.45);

    LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
    boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);

    // Check if enabled and if not send user to the GSP settings
    // Better solution would be to display a dialog and suggesting to 
    // go to the settings
    if (!enabledGPS) {
        Toast.makeText(this, "GPS signal not found", Toast.LENGTH_LONG).show();
        startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
    }

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);

    // Initialize the location fields
    if (location != null) {
        Toast.makeText(this, "Selected Provider " + provider, Toast.LENGTH_SHORT).show();
        meMarker = map.addMarker(
                new MarkerOptions().position(cairo).title("That's Me").snippet("a normal QuranQuiz Node!")
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

        map.moveCamera(CameraUpdateFactory.newLatLngZoom(cairo, 12.0f));

        onLocationChanged(location);
    } else {

        //do something
    }

}

From source file:com.findcab.driver.activity.Signup.java

/**
 * ?GPS?/* w ww  .j a  v a 2  s.  c om*/
 */
private void initLocation() {

    LocationManager locationManager;
    String serviceName = Context.LOCATION_SERVICE;
    locationManager = (LocationManager) this.getSystemService(serviceName);
    // ?
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);

    String provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);
    if (location != null) {

        lat = location.getLatitude();
        lng = location.getLongitude();

    }
}

From source file:org.navitproject.navit.NavitVehicle.java

/**
 * @brief Creates a new {@code NavitVehicle}
 *
 * @param context/*from w w  w  .  j  ava 2 s .c  o  m*/
 * @param pcbid The address of the position callback function called when a location update is received
 * @param scbid The address of the status callback function called when a status update is received
 * @param fcbid The address of the fix callback function called when a
 * {@code android.location.GPS_FIX_CHANGE} is received, indicating a change in GPS fix status
 */
NavitVehicle(Context context, int pcbid, int scbid, int fcbid) {
    if (ContextCompat.checkSelfPermission(context,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // Permission is not granted
        return;
    }
    this.context = context;
    sLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    preciseLocationListener = new NavitLocationListener();
    preciseLocationListener.precise = true;
    fastLocationListener = new NavitLocationListener();

    /* Use 2 LocationProviders, one precise (usually GPS), and one
       not so precise, but possible faster. The fast provider is
       disabled when the precise provider gets its first fix. */

    // Selection criteria for the precise provider
    Criteria highCriteria = new Criteria();
    highCriteria.setAccuracy(Criteria.ACCURACY_FINE);
    highCriteria.setAltitudeRequired(true);
    highCriteria.setBearingRequired(true);
    highCriteria.setCostAllowed(true);
    highCriteria.setPowerRequirement(Criteria.POWER_HIGH);

    // Selection criteria for the fast provider
    Criteria lowCriteria = new Criteria();
    lowCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
    lowCriteria.setAltitudeRequired(false);
    lowCriteria.setBearingRequired(false);
    lowCriteria.setCostAllowed(true);
    lowCriteria.setPowerRequirement(Criteria.POWER_HIGH);

    Log.e("NavitVehicle", "Providers " + sLocationManager.getAllProviders());

    preciseProvider = sLocationManager.getBestProvider(highCriteria, false);
    Log.e("NavitVehicle", "Precise Provider " + preciseProvider);
    fastProvider = sLocationManager.getBestProvider(lowCriteria, false);
    Log.e("NavitVehicle", "Fast Provider " + fastProvider);
    vehicle_pcbid = pcbid;
    vehicle_scbid = scbid;
    vehicle_fcbid = fcbid;

    context.registerReceiver(preciseLocationListener, new IntentFilter(GPS_FIX_CHANGE));
    sLocationManager.requestLocationUpdates(preciseProvider, 0, 0, preciseLocationListener);
    sLocationManager.addGpsStatusListener(preciseLocationListener);

    /*
     * Since Android criteria have no way to specify "fast fix", lowCriteria may return the same
     * provider as highCriteria, even if others are available. In this case, do not register two
     * listeners for the same provider but pick the fast provider manually. (Usually there will
     * only be two providers in total, which makes the choice easy.)
     */
    if (fastProvider == null || preciseProvider.compareTo(fastProvider) == 0) {
        List<String> fastProviderList = sLocationManager.getProviders(lowCriteria, false);
        fastProvider = null;
        for (String fastCandidate : fastProviderList) {
            if (preciseProvider.compareTo(fastCandidate) != 0) {
                fastProvider = fastCandidate;
                break;
            }
        }
    }
    if (fastProvider != null) {
        sLocationManager.requestLocationUpdates(fastProvider, 0, 0, fastLocationListener);
    }
}

From source file:com.findcab.driver.activity.Signup.java

private void initView() {
    context = this;
    back = (Button) findViewById(R.id.back);
    back.setOnClickListener(this);
    start = (Button) findViewById(R.id.start);
    start.setOnClickListener(this);

    edit_name = (EditText) findViewById(R.id.name);
    edit_mobile = (EditText) findViewById(R.id.mobile);
    edit_password = (EditText) findViewById(R.id.password);

    checkBox = (CheckBox) findViewById(R.id.checkBox);

    item = (TextView) findViewById(R.id.item);
    item.setOnClickListener(this);

    if (initGPS()) {

        LocationManager locationManager;
        String serviceName = Context.LOCATION_SERVICE;
        locationManager = (LocationManager) this.getSystemService(serviceName);
        // ?//ww w. jav a2s  . co  m
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);

        String provider = locationManager.getBestProvider(criteria, true);
        location = locationManager.getLastKnownLocation(provider);
        if (location != null) {
            lat = location.getLatitude();
            lng = location.getLongitude();
        }
    }
}