Example usage for android.location Criteria setBearingRequired

List of usage examples for android.location Criteria setBearingRequired

Introduction

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

Prototype

public void setBearingRequired(boolean bearingRequired) 

Source Link

Document

Indicates whether the provider must provide bearing information.

Usage

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);
        // ?/*from   w  w  w . j a va 2  s  .  c om*/
        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();
        }
    }
}

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;/*  ww w .  j  ava2  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:com.rareventure.android.GpsReader.java

public void turnOn() {
    synchronized (lock) {
        //          Log.d(GpsTrailerService.TAG,"Turning on gps");
        if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            GTG.alert(GTGEvent.ERROR_GPS_DISABLED);
            return;
        }//w  ww  .  j  av  a2s.  co m
        if (ActivityCompat.checkSelfPermission(this.ctx,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            GTG.alert(GTGEvent.ERROR_GPS_NO_PERMISSION);
            //            Log.d(GpsTrailerService.TAG,"Failed no permission");
            return;
        }

        if (gpsOn) {
            //            Log.d(GpsTrailerService.TAG,"Gps already on");
            return; //already on
        }
        gpsOn = true;

        //         Log.d(GpsTrailerService.TAG,"Really turning on");
        Criteria criteria = new Criteria();
        criteria.setSpeedRequired(false);
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);

        String providerName = lm.getBestProvider(criteria, true);
        lm.requestLocationUpdates(providerName, prefs.gpsRecurringTimeMs, 0, locationListener, looper);
    }
}

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);
    criteria.setCostAllowed(false);//  w w  w  .j  a va  2s .c o  m
    // criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setSpeedRequired(true);

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

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

public void showCurrentPosition() {
    if (map == null)
        return;//from  w  w  w  . ja  va 2 s. com

    // 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:org.wso2.edgeanalyticsservice.LocationSystemService.java

/** Initialize the location system Service and set the minimal update distance and time  */
public void startLocationService(Context context) {
    mContext = context;/*from   w  w w.j  a va 2  s .c o  m*/
    mLocationManager = (LocationManager) mContext.getSystemService(mContext.LOCATION_SERVICE);
    Criteria locationCritera = new Criteria();
    locationCritera.setAccuracy(Criteria.ACCURACY_COARSE);
    locationCritera.setAltitudeRequired(false);
    locationCritera.setBearingRequired(false);
    locationCritera.setCostAllowed(true);
    locationCritera.setPowerRequirement(Criteria.NO_REQUIREMENT);

    String providerName = mLocationManager.getBestProvider(locationCritera, true);

    if (providerName != null && mLocationManager.isProviderEnabled(providerName)) {
        if (ActivityCompat.checkSelfPermission(mContext,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(mContext,
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public
            // void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            Log.e("Location", "No permission");
            return;
        }
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES,
                (float) MINIMUM_DISTANCE_FOR_UPDATES, new MyLocationListner(), Looper.getMainLooper());
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES,
                (float) MINIMUM_DISTANCE_FOR_UPDATES, new MyLocationListner(), Looper.getMainLooper());
        mlocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        //        mTaskManager.sendLocationData(new double[]{mlocation.getLatitude(), mlocation.getLongitude()});
        mLocationListner = new MyLocationListner();
        synchronized (this) {
            started = true;
        }
    } else {
        // Provider not enabled, prompt user to enable it
        Toast.makeText(mContext, "Please turn on GPS", Toast.LENGTH_LONG).show();
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(myIntent);
    }
}

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

void updateCurrentLocation() {
    if (this.locationListener == null)
        this.locationListener = new LocationListener() {
            @Override//  w  w  w.j  av  a 2 s .  co  m
            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:com.metinkale.prayerapp.vakit.AddCity.java

@SuppressWarnings("MissingPermission")
public void checkLocation() {
    if (PermissionUtils.get(this).pLocation) {
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        Location loc = null;//from  ww  w  .  ja v a  2s. c om
        List<String> providers = lm.getProviders(true);
        for (String provider : providers) {
            Location last = lm.getLastKnownLocation(provider);
            // one hour==1meter in accuracy
            if ((last != null) && ((loc == null)
                    || ((last.getAccuracy() - (last.getTime() / (1000 * 60 * 60))) < (loc.getAccuracy()
                            - (loc.getTime() / (1000 * 60 * 60)))))) {
                loc = last;
            }
        }

        if (loc != null)
            onLocationChanged(loc);

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_MEDIUM);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);
        criteria.setSpeedRequired(false);
        String provider = lm.getBestProvider(criteria, true);
        if (provider != null) {
            lm.requestSingleUpdate(provider, this, null);
        }

    } else {
        PermissionUtils.get(this).needLocation(this);
    }
}

From source file:com.quantcast.measurement.service.QCLocation.java

void setupLocManager(Context appContext) {
    if (appContext == null)
        return;//ww  w .ja  va2s  . com

    _locManager = (LocationManager) appContext.getSystemService(Context.LOCATION_SERVICE);
    if (_locManager != null) {
        //specifically set our Criteria. All we need is a general location
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);
        criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
        criteria.setSpeedRequired(false);

        _myProvider = _locManager.getBestProvider(criteria, true);

        _geocoder = new Geocoder(appContext);
    }
    QCLog.i(TAG, "Setting location provider " + _myProvider);
}

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 ava2 s . 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);
    }
}