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:de.avanux.android.livetracker2.LocationTracker.java

public String getGpsProvider() {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);/*  w w w  .ja v a 2s . co m*/
    criteria.setCostAllowed(false);
    // criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setSpeedRequired(true);

    return getLocationManager().getBestProvider(criteria, true);
}

From source file:com.careme.apvereda.careme.AccumulatorService.java

@Override
public int onStartCommand(Intent intenc, int flags, int idArranque) {
    SharedPreferences sharedPref = getApplicationContext().getSharedPreferences("basicData",
            Context.MODE_PRIVATE);
    String email = sharedPref.getString("email", "");

    //Uncomment to use Nimbees features

    /*if (email.compareTo("") != 0) {
    try {/*w ww.ja v  a  2s  .  c o  m*/
        // Initialize library calling the init method on the Nimbees Client
        NimbeesClient.init(this);
    } catch (NimbeesException e) {
        e.printStackTrace();
    }
    NimbeesClient.getUserManager().register("email", new NimbeesRegistrationCallback() {
        @Override
        public void onSuccess() {
            /* Registration was successful!
            Toast.makeText(getApplicationContext(),
                    "xito en el registro", Toast.LENGTH_LONG).show();
        }
            
        @Override
        public void onFailure(NimbeesException failure) {
            /* Registration failed
            Toast.makeText(getApplicationContext(),
                    "Fallo en el registro", Toast.LENGTH_LONG).show();
        }
    });
    }
    */
    //Toast.makeText(this,"Servicio arrancado "+ idArranque, Toast.LENGTH_SHORT).show();

    // Obtain a reference to the Location Manager
    locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria crit = new Criteria();
    crit.setAccuracy(Criteria.ACCURACY_FINE);
    crit.setPowerRequirement(Criteria.POWER_LOW);
    provider = locManager.getBestProvider(crit, true);

    // And register to obtain current location updates
    locListener = new LocationListener() {
        public void onLocationChanged(Location loc) {
            // Insert a new entry on History
            History history = new History(loc.getLatitude(), loc.getLongitude(), new Date());
            db.insertHistory(history);
            //Uncomment to use Nimbees features
            /*
            try {
            sendPersonalizado(loc);
            } catch (Exception e) {
            }*/
            /*
            Monitor makes the monitoring of the user to determine if he/she has lost
            */
            monitor(loc);
        }

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

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }
    };
    // We want to update the current location every time the user moves MIN_DISTANCE
    locManager.requestLocationUpdates(provider, 0, MIN_DISTANCE, locListener);
    return START_STICKY;
}

From source file:ca.mudar.mtlaucasou.LocationFragmentActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    mAppHelper = (AppHelper) getApplicationContext();
    mActivityHelper = ActivityHelper.createInstance(this);

    prefs = getSharedPreferences(Const.APP_PREFS_NAME, Context.MODE_PRIVATE);
    prefsEditor = prefs.edit();//from   ww w  . j  a  v a  2s  .co m

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

    /**
     * Instantiate a LastLocationFinder class. This will be used to find the
     * last known location when the application starts.
     */
    lastLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this);
    lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener);
    hasRegisteredSingleUpdateReceiver = true;

    /**
     * Set the last known location as user's current location.
     */
    mAppHelper.setLocation(lastLocationFinder.getLastBestLocation(Const.MAX_DISTANCE, Const.MAX_TIME));

    /**
     * Specify the Criteria to use when requesting location updates while
     * the application is Active.
     */
    criteria = new Criteria();
    if (Const.USE_GPS_WHEN_ACTIVITY_VISIBLE) {
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
    } else {
        criteria.setPowerRequirement(Criteria.POWER_LOW);
    }

    /**
     * Setup the location update Pending Intents.
     */
    Intent activeIntent = new Intent(this, LocationChangedReceiver.class);
    locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent passiveIntent = new Intent(this, PassiveLocationChangedReceiver.class);
    locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    locationManager.removeUpdates(locationListenerPassivePendingIntent);

    /**
     * Instantiate a Location Update Requester class based on the available
     * platform version. This will be used to request location updates.
     */
    locationUpdateRequester = PlatformSpecificImplementationFactory
            .getLocationUpdateRequester(this.getApplicationContext(), locationManager);

    super.onCreate(savedInstanceState);
}

From source file:com.hqas.ridetracker.RideTrackerFragment.java

@Override
public void onResume() {
    super.onResume();

    locMan = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    Criteria crit = new Criteria();
    crit.setAccuracy(Criteria.ACCURACY_FINE);
    locMan.requestLocationUpdates(0L, 0.0f, crit, tService, null);
    map.setLocationSource(tService);/*from w w w .  j  ava2s.c o m*/
    broadcastManager = LocalBroadcastManager.getInstance(getActivity());
    broadcastManager.registerReceiver(mapUpdateReceiver,
            new IntentFilter(TrackerService.ACTION_MAP_UPDATE_LOCATION));
    broadcastManager.registerReceiver(startStopReceiver,
            new IntentFilter(TrackerService.ACTION_START_STOP_RECEIVED));
    broadcastManager.registerReceiver(pebbleConnectedReceiver,
            new IntentFilter(TrackerService.ACTION_PEBBLE_CONNECTED));
    broadcastManager.registerReceiver(pebbleConnectedReceiver,
            new IntentFilter(TrackerService.ACTION_PEBBLE_DISCONNECTED));
    broadcastManager.registerReceiver(resetReceiver, new IntentFilter(TrackerService.ACTION_RESET_RECEIVED));

    if (PebbleKit.isWatchConnected(getActivity())) {
        PebbleKit.startAppOnPebble(getActivity(), MainActivity.PEBBLE_APP_UUID);
        pebbleConnected();
    } else {
        pebbleStatus.setText(res.getString(R.string.pebble_status_disconnected));
        pebbleDisconnected();
    }

}

From source file:com.geoffreybuttercrumbs.arewethereyet.ZonePicker.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    setContentView(R.layout.main);/*from  w ww  .ja v a 2 s.c o m*/

    // Setup the map
    setUpMapIfNeeded();
    AlarmOverlay alarmView = (AlarmOverlay) findViewById(R.id.alarm_overlay);
    alarmView.setMap(mMap, this);

    // Set the Behind View
    setBehindContentView(R.layout.menu_frame);
    FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
    mFrag = new DrawerFragment();
    t.replace(R.id.menu_frame, mFrag);
    t.commit();

    // customize the SlidingMenu
    SlidingMenu sm = getSlidingMenu();
    sm.setShadowWidthRes(R.dimen.shadow_width);
    sm.setShadowDrawable(R.drawable.shadow);
    sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    sm.setFadeDegree(0.35f);
    sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //Stop existing alarms
    stopService(new Intent(ZonePicker.this, AlarmService.class));

    //Reset to default ring tone. (Otherwise it is silent!)
    initTone();

    // Acquire a reference to the system Location Manager
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    crit.setAccuracy(Criteria.ACCURACY_FINE);
    Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, updateRange, this);

    //If system has a last known location, use that...
    if (lastKnownLocation != null) {
        zone = new Zone(lastKnownLocation, 1000);
        animateTo(zone.getLocation());
        alarmView.setZone(zone);
    }
    //Else use an arbitrary point
    else {
        Location tempLocation = new Location("");
        tempLocation.setLatitude(42.36544);
        tempLocation.setLongitude(-71.103644);
        zone = new Zone(tempLocation, 1000);
        animateTo(zone.getLocation());
        alarmView.setZone(zone);
    }

    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black));
}

From source file:org.akvo.flow.ui.fragment.SurveyedLocaleListFragment.java

@Override
public void onResume() {
    super.onResume();
    mDatabase.open();//from  w w w  . j  a va  2  s  . c o m

    // try to find out where we are
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String provider = mLocationManager.getBestProvider(criteria, true);
    if (provider != null) {
        Location loc = mLocationManager.getLastKnownLocation(provider);
        if (loc != null) {
            mLatitude = loc.getLatitude();
            mLongitude = loc.getLongitude();
        }
    }
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);

    // Listen for data sync updates, so we can update the UI accordingly
    getActivity().registerReceiver(dataSyncReceiver, new IntentFilter(getString(R.string.action_data_sync)));

    refresh();
}

From source file:com.cloudbees.gasp.activity.GaspLocationsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_locations);

    GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    LocationManager locationManager;/*from  w  w  w  .ja  v a2  s .  c om*/
    String svcName = Context.LOCATION_SERVICE;
    locationManager = (LocationManager) 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 location = locationManager.getLastKnownLocation(provider);
    Log.i(TAG, "CURRENT LOCATION");
    Log.i(TAG, "Latitude = " + location.getLatitude());
    Log.i(TAG, "Longitude = " + location.getLongitude());

    if (location != null) {
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();
        Geocoder gc = new Geocoder(this, Locale.getDefault());

        if (!Geocoder.isPresent())
            Log.i(TAG, "No geocoder available");
        else {
            try {
                List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
                StringBuilder sb = new StringBuilder();
                if (addresses.size() > 0) {
                    Address address = addresses.get(0);

                    for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
                        sb.append(address.getAddressLine(i)).append(" ");

                    sb.append(address.getLocality()).append("");
                    sb.append(address.getPostalCode()).append(" ");
                    sb.append(address.getCountryName());
                }
                Log.i(TAG, "Address: " + sb.toString());
            } catch (IOException e) {
                Log.d(TAG, "IOException getting address from geocoder", e);
            }
        }
    }

    map.setMyLocationEnabled(true);

    LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude());
    CameraPosition cameraPosition = new CameraPosition.Builder().target(myLocation).zoom(16).bearing(0).tilt(0)
            .build();
    map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    new LocationMapper().execute();
}

From source file:dtu.ds.warnme.app.location.FollowMeLocationSource.java

private void init() {
    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
    criteria.setAltitudeRequired(true);//from w  w  w.  j  ava 2s. c o m
    criteria.setBearingRequired(true);
    criteria.setSpeedRequired(true);
    criteria.setCostAllowed(true);
}

From source file:org.akvo.flow.ui.fragment.MapFragment.java

/**
 * Center the map in the given record's coordinates. If no record is provided,
 * the user's location will be used./*from ww w  . j a  va 2  s.  c  om*/
 * @param record
 */
private void centerMap(SurveyedLocale record) {
    if (mMap == null) {
        return; // Not ready yet
    }

    LatLng position = null;

    if (record != null && record.getLatitude() != null && record.getLongitude() != null) {
        // Center the map in the data point
        position = new LatLng(record.getLatitude(), record.getLongitude());
    } else {
        // When multiple points are shown, center the map in user's location
        LocationManager manager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        String provider = manager.getBestProvider(criteria, true);
        if (provider != null) {
            Location location = manager.getLastKnownLocation(provider);
            if (location != null) {
                position = new LatLng(location.getLatitude(), location.getLongitude());
            }
        }
    }

    if (position != null) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, 10));
    }
}

From source file:org.akvo.flow.activity.GeoshapeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.geoshape_activity);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mFeatures = new ArrayList<>();
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    mFeatureMenu = findViewById(R.id.feature_menu);
    mFeatureName = (TextView) findViewById(R.id.feature_name);
    mClearPointBtn = findViewById(R.id.clear_point_btn);
    mClearPointBtn.setOnClickListener(mFeatureMenuListener);
    findViewById(R.id.add_point_btn).setOnClickListener(mFeatureMenuListener);
    findViewById(R.id.clear_feature_btn).setOnClickListener(mFeatureMenuListener);
    findViewById(R.id.properties).setOnClickListener(mFeatureMenuListener);

    mAllowPoints = getIntent().getBooleanExtra(ConstantUtil.EXTRA_ALLOW_POINTS, true);
    mAllowLine = getIntent().getBooleanExtra(ConstantUtil.EXTRA_ALLOW_LINE, true);
    mAllowPolygon = getIntent().getBooleanExtra(ConstantUtil.EXTRA_ALLOW_POLYGON, true);
    mManualInput = getIntent().getBooleanExtra(ConstantUtil.EXTRA_MANUAL_INPUT, true);

    initMap();//w ww  .ja  va  2 s . com

    String geoJSON = getIntent().getStringExtra(ConstantUtil.GEOSHAPE_RESULT);
    if (!TextUtils.isEmpty(geoJSON)) {
        load(geoJSON);
    } else {
        // If user location is known, center map
        LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        String provider = manager.getBestProvider(criteria, true);
        if (provider != null) {
            Location location = manager.getLastKnownLocation(provider);
            if (location != null) {
                LatLng position = new LatLng(location.getLatitude(), location.getLongitude());
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, 10));
            }
        }
    }
}