Example usage for android.location Criteria ACCURACY_FINE

List of usage examples for android.location Criteria ACCURACY_FINE

Introduction

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

Prototype

int ACCURACY_FINE

To view the source code for android.location Criteria ACCURACY_FINE.

Click Source Link

Document

A constant indicating a finer location accuracy requirement

Usage

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private void getBestProvider(LocationManager lm) {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);

    String bestProvider = lm.getBestProvider(criteria, true);
    if (bestProvider != null) {
        lm.requestLocationUpdates(bestProvider, 0, 0, this);
        location = lm.getLastKnownLocation(bestProvider);
        for (InputLayout input : locationInputs) {
            input.setLocation(location);
        }//from   w  w  w.  j  a v a 2  s.c o  m

    } else {
        new AlertDialog.Builder(this).setMessage(R.string.need_location).setCancelable(true)
                .setPositiveButton(R.string.enable_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        launchGpsSettings();
                        dialog.dismiss();
                    }
                }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create().show();
    }
}

From source file:se.team05.activity.RouteActivity.java

/**
 * Sets up the location manager, location lsitener and some criteria that
 * ask for the gps provider (fine). Then add overlay for my location and the
 * trace of the user's route.//from  www  . j  av a  2s  . c o  m
 */
private void setupMyLocationAndListener() {
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mapLocationListener = new MapLocationListener(this, route.isNewRoute(), route.getCheckPoints());
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mapLocationListener);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setCostAllowed(false);
    String providerName = locationManager.getBestProvider(criteria, true);
    if (providerName != null) {
        Log.d(TAG, getString(R.string.provider_) + providerName);
    }
    myLocationOverlay = new MyLocationOverlay(this, mapView);
    overlays.add(myLocationOverlay);
    RouteOverlay userRouteOverlay = new RouteOverlay(route.getGeoPoints(), USER_ROUTE_COLOR);
    overlays.add(userRouteOverlay);
}

From source file:org.deviceconnect.android.deviceplugin.host.profile.HostGeolocationProfile.java

/**
 * ??./*w  ww  .  ja  v a2s .  c om*/
 * @param accuracy .
 * @param interval ?.
 */
private void startGPS(final boolean accuracy, final int interval) {
    if (ActivityCompat.checkSelfPermission(getContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getContext(),
                    ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    Criteria criteria = new Criteria();
    if (accuracy) {
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
    } else {
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    }

    mLocationManager.requestLocationUpdates(mLocationManager.getBestProvider(criteria, true), interval, 0, this,
            Looper.getMainLooper());
}

From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java

/**
     *//  w w  w. j a  v  a2s .co  m
     * @param value set true to engage "aggressive", battery-consuming tracking, false for stationary-region tracking
     */
    private void setPace(Boolean value) {
        Log.i(TAG, "setPace: " + value);

        Boolean wasMoving = isMoving;
        isMoving = value;
        isAcquiringStationaryLocation = false;
        isAcquiringSpeed = false;
        stationaryLocation = null;

        locationManager.removeUpdates(this);

        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setHorizontalAccuracy(translateDesiredAccuracy(desiredAccuracy));
        criteria.setPowerRequirement(Criteria.POWER_HIGH);

        if (isMoving) {
            // setPace can be called while moving, after distanceFilter has been recalculated.  We don't want to re-acquire velocity in this case.
            if (!wasMoving) {
                isAcquiringSpeed = true;
            }
        } else {
            isAcquiringStationaryLocation = true;
        }

        // Temporarily turn on super-aggressive geolocation on all providers when acquiring velocity or stationary location.
        if (isAcquiringSpeed || isAcquiringStationaryLocation) {
            locationAcquisitionAttempts = 0;
            // Turn on each provider aggressively for a short period of time
            List<String> matchingProviders = locationManager.getAllProviders();
            for (String provider : matchingProviders) {
                if (provider != LocationManager.PASSIVE_PROVIDER) {
                    locationManager.requestLocationUpdates(provider, 0, 0, this);
                }
            }
        } else {
            locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true),
                    locationTimeout * 1000, scaledDistanceFilter, this);
        }
    }

From source file:de.madvertise.android.sdk.MadvertiseUtil.java

/**
 * Try to update current location. Non blocking call.
 * /*from w ww. j a  v a2  s . c  o  m*/
 * @param context
 *            application context
 */
public static void refreshCoordinates(final Context context) {
    MadvertiseUtil.logMessage(null, Log.DEBUG, "Trying to refresh location");

    if (context == null) {
        MadvertiseUtil.logMessage(null, Log.DEBUG, "Context not set - quit location refresh");
        return;
    }

    // check if we need a regular update
    if ((sLocationUpdateTimestamp + MadvertiseUtil.SECONDS_TO_REFRESH_LOCATION * 1000) > System
            .currentTimeMillis()) {
        MadvertiseUtil.logMessage(null, Log.DEBUG, "It's not time yet for refreshing the location");
        return;
    }

    synchronized (context) {
        // recheck, if location was updated by another thread while we
        // paused
        if ((sLocationUpdateTimestamp + MadvertiseUtil.SECONDS_TO_REFRESH_LOCATION * 1000) > System
                .currentTimeMillis()) {
            MadvertiseUtil.logMessage(null, Log.DEBUG, "Another thread updated the loation already");
            return;
        }

        boolean permissionCoarseLocation = MadvertiseUtil
                .checkPermissionGranted(android.Manifest.permission.ACCESS_COARSE_LOCATION, context);
        boolean permissionFineLocation = MadvertiseUtil
                .checkPermissionGranted(android.Manifest.permission.ACCESS_FINE_LOCATION, context);

        // return (null) if we do not have any permissions
        if (!permissionCoarseLocation && !permissionFineLocation) {
            MadvertiseUtil.logMessage(null, Log.DEBUG, "No permissions for requesting the location");
            return;
        }

        // return (null) if we can't get a location manager
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        if (locationManager == null) {
            MadvertiseUtil.logMessage(null, Log.DEBUG, "Unable to fetch a location manger");
            return;
        }

        String provider = null;
        Criteria criteria = new Criteria();
        criteria.setCostAllowed(false);

        // try to get coarse location first
        if (permissionCoarseLocation) {
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            provider = locationManager.getBestProvider(criteria, true);
        }

        // try to get gps location if coarse locatio did not work
        if (provider == null && permissionFineLocation) {
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            provider = locationManager.getBestProvider(criteria, true);
        }

        // still no provider, return (null)
        if (provider == null) {
            MadvertiseUtil.logMessage(null, Log.DEBUG, "Unable to fetch a location provider");
            return;
        }

        // create a finalized reference to the location manager, in order to
        // access it in the inner class
        final LocationManager finalizedLocationManager = locationManager;
        sLocationUpdateTimestamp = System.currentTimeMillis();
        locationManager.requestLocationUpdates(provider, 0, 0, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                MadvertiseUtil.logMessage(null, Log.DEBUG, "Refreshing location");
                sCurrentLocation = location;
                sLocationUpdateTimestamp = System.currentTimeMillis();
                // stop draining battery life
                finalizedLocationManager.removeUpdates(this);
            }

            // not used yet
            @Override
            public void onProviderDisabled(String provider) {
            }

            @Override
            public void onProviderEnabled(String provider) {
            }

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

From source file:org.berlin_vegan.bvapp.activities.LocationsOverviewActivity.java

private void requestGpsLocationUpdates() {
    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String provider = mLocationManager.getBestProvider(criteria, true);
    if (provider != null) {
        mGpsProviderAvailable = true;/*w w w . ja  v  a2s  .  co m*/
        mLocationManager.requestSingleUpdate(criteria, mLocationListener, null);
    } else {
        mGpsProviderAvailable = false;
    }
}

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);// w  ww.  j av  a  2 s.c  o m
    c.setBearingRequired(false);
    c.setSpeedRequired(false);
    c.setCostAllowed(true);
    c.setPowerRequirement(Criteria.POWER_HIGH);
    return c;

}

From source file:com.example.mapdemo.BasicMapDemoActivity.java

private void setGeoLocation() {
    latitude = (TextView) findViewById(R.id.lat);
    longitude = (TextView) findViewById(R.id.lon);
    altitude = (TextView) findViewById(R.id.alt);
    heading = (TextView) findViewById(R.id.hea);

    provText = (TextView) findViewById(R.id.prov);
    choice = (TextView) findViewById(R.id.choice);
    fineAcc = (CheckBox) findViewById(R.id.fineAccuracy);
    choose = (Button) findViewById(R.id.chooseRadio);
    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE); //default

    // user defines the criteria
    choose.setOnClickListener(new View.OnClickListener() {
        @Override//from w w  w.j  a  v a  2  s  .  co  m
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (fineAcc.isChecked()) {
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                choice.setText("fine accuracy selected");
            } else {
                criteria.setAccuracy(Criteria.ACCURACY_COARSE);
                choice.setText("coarse accuracy selected");
            }
        }
    });
    criteria.setCostAllowed(false);
    // get the best provider depending on the criteria
    provider = locationManager.getBestProvider(criteria, false);
    // the last known location of this provider
    Location location = locationManager.getLastKnownLocation(provider);
    mylistener = new MyLocationListener();
    if (location != null) {
        mylistener.onLocationChanged(location);
    } else {
        // leads to the settings because there is no last known location
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }
    // location updates: at least 1 meter and 200 millsecs change
    locationManager.requestLocationUpdates(provider, 200, 1, mylistener);
}

From source file:org.opensmc.mytracks.cyclesmc.MainInput.java

private LatLng myCurrentLocation() {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    Location loc = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
    if (loc != null) {
        return new LatLng(loc.getLatitude(), loc.getLongitude());
    } else {/*from   w  w  w  .  ja  va  2s  .c  om*/
        // try with coarse accuracy
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        loc = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));

        if (loc == null) {
            return new LatLng(39.952451, -75.163664); // city hall by default
        }
    }
    return null;
}