Example usage for android.location Criteria setHorizontalAccuracy

List of usage examples for android.location Criteria setHorizontalAccuracy

Introduction

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

Prototype

public void setHorizontalAccuracy(int accuracy) 

Source Link

Document

Indicates the desired horizontal accuracy (latitude and longitude).

Usage

From source file:net.frakbot.FWeather.util.LocationHelper.java

/**
 * Returns the default criteria set for the LocationManager.
 * @return the default Criteria//w  w w.j a v a  2  s.c om
 */
private static Criteria getDefaultCriteria() {
    Criteria criteria = new Criteria();
    criteria.setCostAllowed(false);
    criteria.setHorizontalAccuracy(Criteria.ACCURACY_LOW);
    criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
    criteria.setSpeedRequired(false);
    criteria.setPowerRequirement(Criteria.POWER_LOW);

    return criteria;
}

From source file:ch.hesso.master.sweetcity.activity.map.MapActivity.java

public void showCurrentPosition() {
    if (map == null)
        return;/*from   ww  w . j a  va2 s.co m*/

    // Enabling MyLocation Layer of Google Map
    map.setMyLocationEnabled(true);

    Criteria lightCriteria = new Criteria();
    lightCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
    lightCriteria.setAltitudeRequired(false);
    lightCriteria.setBearingRequired(false);
    lightCriteria.setCostAllowed(false);
    lightCriteria.setHorizontalAccuracy(Criteria.ACCURACY_MEDIUM);
    lightCriteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
    lightCriteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT);
    lightCriteria.setSpeedRequired(false);

    listener = new MapLocationListener(map);

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    locationManager.requestSingleUpdate(lightCriteria, listener, null);
    locationProvider = locationManager.getBestProvider(new Criteria(), true);
    Location location = locationManager.getLastKnownLocation(locationProvider);

    if (location != null) {
        listener.onLocationChanged(location);
        map.animateCamera(CameraUpdateFactory.zoomTo(15));
    }
}

From source file:ch.hesso.master.sweetcity.activity.report.ReportActivity.java

void updateCurrentLocation() {
    if (this.locationListener == null)
        this.locationListener = new LocationListener() {
            @Override/*from w w w  .j a  v  a  2 s.  com*/
            public void onLocationChanged(Location location) {
                ReportActivity.this.currentLocation = location;
            }

            @Override
            public void onProviderDisabled(String provider) {
            }

            @Override
            public void onProviderEnabled(String provider) {
            }

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

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(false);
    criteria.setHorizontalAccuracy(Criteria.ACCURACY_MEDIUM);
    criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
    criteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT);
    criteria.setSpeedRequired(false);

    LocationManager locationManager = (LocationManager) ReportActivity.this.getSystemService(LOCATION_SERVICE);
    locationManager.requestSingleUpdate(criteria, this.locationListener, null);
}

From source file:name.gumartinm.weather.information.activity.MapActivity.java

public void onClickGetLocation(final View v) {
    // TODO: Somehow I should show a progress dialog.
    // If Google Play Services is available
    if (this.mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        // TODO: Hopefully there will be results even if location did not change...   
        final Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);//from   ww  w.  j a  v a2s .  c  om
        criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
        criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
        criteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setSpeedRequired(false);
        criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);

        this.mLocationManager.requestSingleUpdate(criteria, this, null);
    } else {
        Toast.makeText(this, this.getString(R.string.weather_map_not_enabled_location), Toast.LENGTH_LONG)
                .show();
    }
    // Trying to use the synchronous calls. Problems: mGoogleApiClient read/store from different threads.
    // new GetLocationTask(this).execute();
}