Example usage for android.location Criteria setAccuracy

List of usage examples for android.location Criteria setAccuracy

Introduction

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

Prototype

public void setAccuracy(int accuracy) 

Source Link

Document

Indicates the desired accuracy for latitude and longitude.

Usage

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./*  w w w.  ja v  a  2  s. com*/
 */
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:net.jongrakko.zipsuri.activity.PostUploadActivity.java

@Override
public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
        switch (buttonView.getId()) {
        case R.id.radioButtonAddressGPS:
            mEditTextAddress.setOnClickListener(null);
            this.mGoogleMap.setOnMapClickListener(this);
            this.mGoogleMap.setOnMyLocationButtonClickListener(this);

            if (ContextCompat.checkSelfPermission(getContext(),
                    Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                mGoogleMap.setMyLocationEnabled(true);
                LocationProvider lprovider;
                LocationManager lm = (LocationManager) getActivity()
                        .getSystemService(getActivity().LOCATION_SERVICE);
                lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
                lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
                String provider;//from ww  w  . jav  a  2 s. c  o m
                Criteria criteria = new Criteria();
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                criteria.setPowerRequirement(Criteria.POWER_HIGH);
                provider = lm.getBestProvider(criteria, true);

                if (provider == null || provider.equals("passive")) { // ? ?    ??
                    new AlertDialog.Builder(getActivity()).setTitle(" ??")
                            .setNeutralButton("??", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                    buttonView.toggle();
                                    startActivityForResult(
                                            new Intent(
                                                    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                            0);
                                }
                            }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                                @Override
                                public void onCancel(DialogInterface dialog) {
                                    dialog.dismiss();
                                }
                            }).show();
                } else { //  ? ?   
                    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this);
                    Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    if (l != null) {
                        Log.e("hello??", "okok");
                    }
                }

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                            MY_LOCATION_REQUEST_CODE);
                }
            }
            break;
        case R.id.radioButtonAddressSelf:
            this.mGoogleMap.setOnMapClickListener(null);
            mEditTextAddress.setOnClickListener(this);
            this.mGoogleMap.setOnMyLocationButtonClickListener(null);
            mGoogleMap.setMyLocationEnabled(false);
            mEditTextAddress.setOnClickListener(this);
            startActivityForResult(new Intent(getContext(), SearchAddressActivity.class), SEARCH_ADDRESS);
            break;
        }
    }
}

From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetDrive.java

private final void init_location() {
    pref_app = PreferenceManager.getDefaultSharedPreferences(this);
    new Thread(new Runnable() {
        @Override//from   ww  w  .  j  ava  2 s.c o m
        public final void run() {
            try {
                final Criteria criteria = new Criteria();
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                criteria.setPowerRequirement(Criteria.POWER_HIGH);
                mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
                if (mLocationManager != null) {
                    // final String provider = manager.getBestProvider(criteria, true);
                    boolean provider_flag = false;
                    final List<String> providers = mLocationManager.getProviders(true);
                    for (final String provider : providers) {
                        if ((provider.equals(LocationManager.GPS_PROVIDER))
                                || (provider.equals(LocationManager.NETWORK_PROVIDER))) {
                            if (mLocationManager.isProviderEnabled(provider)) {
                                provider_flag = true;
                            }
                        }
                        WriteLog.write(UpdateTweetDrive.this, "requestLocationUpdates() provider: " + provider);

                        final int pref_locationinfo_mintime = ListAdapter.getPrefInt(UpdateTweetDrive.this,
                                "pref_locationinfo_mintime", "300000");
                        try {
                            new Runnable() {
                                @Override
                                public final void run() {
                                    if (ContextCompat.checkSelfPermission(UpdateTweetDrive.this,
                                            android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                                        mLocationManager.requestLocationUpdates(provider,
                                                pref_locationinfo_mintime, 0, UpdateTweetDrive.this);
                                    } else {
                                        if (Build.VERSION.SDK_INT >= 23)
                                            requestPermissions(
                                                    new String[] {
                                                            android.Manifest.permission.ACCESS_FINE_LOCATION },
                                                    REQUEST_PERMISSION);
                                    }
                                }
                            };
                        } catch (final Exception e) {
                            WriteLog.write(UpdateTweetDrive.this, e);
                        }
                    }

                    if (startup_flag == true) {
                        startup_flag = false;

                        if (provider_flag == false) {
                            toast(getString(R.string.open_location_source_settings));
                            try {
                                startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"));
                            } catch (final ActivityNotFoundException e) {
                                WriteLog.write(UpdateTweetDrive.this, e);
                            } catch (final Exception e) {
                                WriteLog.write(UpdateTweetDrive.this, e);
                            }
                        }
                    }
                }
            } catch (final IllegalArgumentException e) {
                WriteLog.write(UpdateTweetDrive.this, e);
            } catch (final RuntimeException e) {
                WriteLog.write(UpdateTweetDrive.this, e);
            }

        }
    }).start();
}

From source file:com.ht.app.RestaurantsActivity.java

private Location getLastKnownLocation() {
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    String provider = lm.getBestProvider(criteria, true);
    if (provider == null) {
        return null;
    }//  www .  j  av  a  2 s. c  o m
    return lm.getLastKnownLocation(provider);
}

From source file:com.xmobileapp.rockplayer.LastFmEventImporter.java

/*********************************
 * //  w w  w  .ja  va2s . c  o  m
 * Constructor
 * @param context
 * 
 *********************************/
public LastFmEventImporter(Context context) {
    this.context = context;

    Log.i("LASTFMEVENT", "creating-------------------------");
    /*
     * Check for Internet Connection (Through whichever interface)
     */
    ConnectivityManager connManager = (ConnectivityManager) ((RockPlayer) context)
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connManager.getActiveNetworkInfo();
    /******* EMULATOR HACK - false condition needs to be removed *****/
    //if (false && (netInfo == null || !netInfo.isConnected())){
    if ((netInfo == null || !netInfo.isConnected())) {
        Bundle data = new Bundle();
        data.putString("info", "No Internet Connection");
        Message msg = new Message();
        msg.setData(data);
        ((RockPlayer) context).analyseConcertInfoHandler.sendMessage(msg);
        return;
    }

    /*
     * Get location
     */
    MIN_UPDATE_INTVL = 5 * 24 * 60 * 60 * 1000; // 5 days
    SPREAD_INTVL = 21 * 24 * 60 * 60 * 1000; // 21 days;
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (locManager.getBestProvider(criteria, true) != null)
        myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(criteria, true));
    else {
        myLocation = new Location("gps");
        myLocation.setLatitude(47.100301);
        myLocation.setLongitude(-119.982465);
    }

    /*
     * Get preferred distance
     */
    //      SharedPreferences prefs = ((Filex) context).getSharedPreferences(((Filex) context).PREFS_NAME, 0);
    RockOnPreferenceManager prefs = new RockOnPreferenceManager(((RockPlayer) context).FILEX_PREFERENCES_PATH);
    concertRadius = prefs.getLong("ConcertRadius", (long) (((RockPlayer) context).CONCERT_RADIUS_DEFAULT));

    //myLocation =  locManager.getLastKnownLocation(locManager.getBestProvider(Criteria.POWER_LOW, true));

    //      try {
    //         getArtistEvents();
    //      } catch (SAXException e) {
    //         e.printStackTrace();
    //      } catch (ParserConfigurationException e) {
    //         e.printStackTrace();
    //      }
}

From source file:com.google.ytd.SubmitActivity.java

private void getVideoLocation() {
    this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_HIGH);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);//w w w .  j  a  v a2 s . c o  m
    criteria.setSpeedRequired(false);
    criteria.setCostAllowed(true);

    String provider = locationManager.getBestProvider(criteria, true);

    this.locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                SubmitActivity.this.videoLocation = location;
                double lat = location.getLatitude();
                double lng = location.getLongitude();
                Log.d(LOG_TAG, "lat=" + lat);
                Log.d(LOG_TAG, "lng=" + lng);

                TextView locationText = (TextView) findViewById(R.id.locationLabel);
                locationText.setText("Geo Location: " + String.format("lat=%.2f lng=%.2f", lat, lng));
                locationManager.removeUpdates(this);
            } else {
                Log.d(LOG_TAG, "location is null");
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

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

    };

    if (provider != null) {
        locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);
    }
}

From source file:org.mariotaku.twidere.activity.ComposeActivity.java

/**
 * The Location Manager manages location providers. This code searches for
 * the best provider of data (GPS, WiFi/cell phone tower lookup, some other
 * mechanism) and finds the last known location.
 **//* w  ww  .  jav  a  2 s. c om*/
private boolean getLocation() {
    final Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    final String provider = mLocationManager.getBestProvider(criteria, true);

    if (provider != null) {
        final Location location;
        if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        } else {
            location = mLocationManager.getLastKnownLocation(provider);
        }
        if (location == null) {
            mLocationManager.requestLocationUpdates(provider, 0, 0, this);
            setSupportProgressBarIndeterminateVisibility(true);
        }
        mRecentLocation = location != null ? new ParcelableLocation(location) : null;
    } else {
        Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show();
    }
    return provider != null;
}

From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java

/**
 * Get provider name.//from  w  w  w .  j  av  a2s . com
 * @return Name of best suiting provider.
 * */
String getProviderName() {
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setPowerRequirement(Criteria.POWER_LOW); // Chose your desired power consumption level.
    criteria.setAccuracy(Criteria.ACCURACY_FINE); // Choose your accuracy requirement.
    criteria.setSpeedRequired(false); // Chose if speed for first location fix is required.
    criteria.setAltitudeRequired(false); // Choose if you use altitude.
    criteria.setBearingRequired(false); // Choose if you use bearing.
    criteria.setCostAllowed(false); // Choose if this provider can waste money :-)

    // Provide your criteria and flag enabledOnly that tells
    // LocationManager only to return active providers.
    return locationManager.getBestProvider(criteria, true);
}

From source file:com.example.angel.parkpanda.MainActivity.java

public Location moveMyPosCamera() {

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }// w  ww.  j  a  v  a 2s. c om
    Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (myLocation == null) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        String provider = lm.getBestProvider(criteria, true);
        myLocation = lm.getLastKnownLocation(provider);
    }
    return myLocation;
}

From source file:com.brejza.matt.habmodem.Dsp_service.java

private void enableLocation() {
    //my location part
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);

    String bestProvider = this.locationManager.getBestProvider(criteria, true);
    if (bestProvider == null)
        return;//from  ww  w. j  ava2  s  . co  m
    System.out.println("STARTING GPS WITH: " + bestProvider);
    logEvent("Starting Location with: " + bestProvider, true);
    this.locationManager.requestLocationUpdates(bestProvider, 2000, 0, this.loc_han);

}