當前位置: 首頁>>代碼示例>>Java>>正文


Java Criteria.setAccuracy方法代碼示例

本文整理匯總了Java中android.location.Criteria.setAccuracy方法的典型用法代碼示例。如果您正苦於以下問題:Java Criteria.setAccuracy方法的具體用法?Java Criteria.setAccuracy怎麽用?Java Criteria.setAccuracy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.location.Criteria的用法示例。


在下文中一共展示了Criteria.setAccuracy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCriteria

import android.location.Criteria; //導入方法依賴的package包/類
/**
 * 設置定位參數
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    // 設置定位精確度 Criteria.ACCURACY_COARSE比較粗略,Criteria.ACCURACY_FINE則比較精細
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 設置是否要求速度
    criteria.setSpeedRequired(false);
    // 設置是否允許運營商收費
    criteria.setCostAllowed(false);
    // 設置是否需要方位信息
    criteria.setBearingRequired(false);
    // 設置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 設置對電源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:LocationUtils.java

示例2: getLocation

import android.location.Criteria; //導入方法依賴的package包/類
public static String getLocation(Context context) {
    if (context == null) {
        return "";
    }
    try {
        LocationManager locationManager = (LocationManager) context.getSystemService(HOME_RECOMMEND_PARAMETERS.LOCATION);
        Criteria criteria = new Criteria();
        criteria.setCostAllowed(false);
        criteria.setAccuracy(2);
        String bestProvider = locationManager.getBestProvider(criteria, true);
        if (bestProvider != null) {
            Location lastKnownLocation = locationManager.getLastKnownLocation(bestProvider);
            if (lastKnownLocation == null) {
                return "";
            }
            double latitude = lastKnownLocation.getLatitude();
            g = latitude + "*" + lastKnownLocation.getLongitude();
            return g;
        }
    } catch (Throwable e) {
        f.b("getLocation", "getLocation>>>", e);
    }
    return "";
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:25,代碼來源:Util.java

示例3: getLocation

import android.location.Criteria; //導入方法依賴的package包/類
public static String getLocation(Context context) {
    if (context == null) {
        return "";
    }
    try {
        LocationManager locationManager = (LocationManager) context.getSystemService
                ("location");
        Criteria criteria = new Criteria();
        criteria.setCostAllowed(false);
        criteria.setAccuracy(2);
        String bestProvider = locationManager.getBestProvider(criteria, true);
        if (bestProvider != null) {
            Location lastKnownLocation = locationManager.getLastKnownLocation(bestProvider);
            if (lastKnownLocation == null) {
                return "";
            }
            double latitude = lastKnownLocation.getLatitude();
            g = latitude + "*" + lastKnownLocation.getLongitude();
            return g;
        }
    } catch (Throwable e) {
        f.b("getLocation", "getLocation>>>", e);
    }
    return "";
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:26,代碼來源:Util.java

示例4: requestLocation

import android.location.Criteria; //導入方法依賴的package包/類
private void requestLocation(Context context, int i) {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(i);
    String bestProvider = this.mLocationManager.getBestProvider(criteria, true);
    if (bestProvider != null) {
        this.mProvider = bestProvider;
    }
    Log.d(TAG, "Get location from " + this.mProvider);
    try {
        if (!TextUtils.isEmpty(this.mProvider)) {
            Location lastKnownLocation = this.mLocationManager.getLastKnownLocation(this
                    .mProvider);
            if (lastKnownLocation != null) {
                this.mLocation = lastKnownLocation;
            } else if (this.mLocationManager.isProviderEnabled(this.mProvider) && this
                    .mListener != null && (context instanceof Activity)) {
                this.mLocationManager.requestLocationUpdates((Activity) context, this
                        .mProvider, 1, 0.0f, this.mListener);
            }
        }
    } catch (IllegalArgumentException e) {
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:24,代碼來源:DefaultLocationProvider.java

示例5: getCriteria

import android.location.Criteria; //導入方法依賴的package包/類
/**
 * 設置定位參數
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    //設置定位精確度 Criteria.ACCURACY_COARSE比較粗略,Criteria.ACCURACY_FINE則比較精細
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    //設置是否要求速度
    criteria.setSpeedRequired(false);
    // 設置是否允許運營商收費
    criteria.setCostAllowed(false);
    //設置是否需要方位信息
    criteria.setBearingRequired(false);
    //設置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 設置對電源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
開發者ID:tututututututu,項目名稱:BaseCore,代碼行數:22,代碼來源:LocationUtils.java

示例6: onPostCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
protected void onPostCreate(Bundle savedInstanceState) {
	super.onPostCreate(savedInstanceState);
	setContentView(R.layout.activity_location);

	tv_location = (TextView) findViewById(R.id.tv_location);

	LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
	Criteria criteria = new Criteria();
	criteria.setCostAllowed(true);
	criteria.setAccuracy(Criteria.ACCURACY_FINE);
	String bestProvider = lm.getBestProvider(criteria, true);

	MyLocationListener myLocationListener = new MyLocationListener();
	lm.requestLocationUpdates(bestProvider, 0, 0, myLocationListener);

}
 
開發者ID:REIGE,項目名稱:AndroidTest,代碼行數:18,代碼來源:activity_location.java

示例7: setupLocationChangeListener

import android.location.Criteria; //導入方法依賴的package包/類
@SuppressLint("MissingPermission")
private void setupLocationChangeListener() {
/* SETTING UP LOCATION CHANGE LISTENER */
    locationListener = new LocationListener();
    locationManager = (LocationManager) Application.getContext().getSystemService(Context.LOCATION_SERVICE);
    locationServiceEnabled = locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

    Criteria criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(true);
    criteria.setSpeedRequired(false);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setCostAllowed(true);

    bestProvider = locationManager.getBestProvider(criteria, false);

    updateFrequency = Integer.parseInt(settingsSharedPreferences.getString("update_frequency", "5")) * 1000;

    locationManager.requestLocationUpdates(bestProvider, updateFrequency, 0, locationListener);
}
 
開發者ID:STUDIO-apps,項目名稱:GeoShare_Android,代碼行數:22,代碼來源:MapsFragment.java

示例8: onCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
public void onCreate() {
	super.onCreate();
	//��ȡ�ֻ��ľ�γ������
	//1,��ȡλ�ù����߶���
	LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
	//2,�����ŵķ�ʽ��ȡ��γ������()
	Criteria criteria = new Criteria();
	//������
	criteria.setCostAllowed(true);
	criteria.setAccuracy(Criteria.ACCURACY_FINE);//ָ����ȡ��γ�ȵľ�ȷ��
	String bestProvider = lm.getBestProvider(criteria, true);
	//3,��һ��ʱ����,�ƶ�һ��������ȡ��γ������
	MyLocationListener myLocationListener = new MyLocationListener();
	lm.requestLocationUpdates(bestProvider, 0, 0, myLocationListener);
}
 
開發者ID:cckevincyh,項目名稱:mobilesafe,代碼行數:17,代碼來源:LocationService.java

示例9: onCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);

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

    startTime = System.currentTimeMillis();
    try {
        locationManager.requestSingleUpdate(criteria, this, null);
    } catch (SecurityException e) {
        Log.e(TAG, "permission not granted");
    }
}
 
開發者ID:tranquvis,項目名稱:SimpleSmsRemote,代碼行數:19,代碼來源:TestActivity.java

示例10: onCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    manager = (LocationManager) getSystemService(LOCATION_SERVICE);
    listener = new MyListener();
    //criteria 查詢條件
    //true 隻返回可用的位置提供者
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);//獲取精確的位置
    criteria.setCostAllowed(true);//允許產生開銷
    String name = manager.getBestProvider(criteria, true);
    System.out.println("最好的位置提供者:" + name);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, 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.
        return;
    }
    manager.requestLocationUpdates(name, 0, 0, listener);
}
 
開發者ID:sh2zqp,項目名稱:MobilePhoneSafeProtector,代碼行數:26,代碼來源:GPSLocationService.java

示例11: onCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    // locate
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // check permission
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    // get best provider
    Criteria criteria = new Criteria();
    criteria.setCostAllowed(true);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String bestProvider = locationManager.getBestProvider(criteria, true);
    System.out.println("best provider:" + bestProvider);
    // start listening
    listener = new MyLocationListener();
    locationManager.requestLocationUpdates(bestProvider, 0, 0, listener);
}
 
開發者ID:ittianyu,項目名稱:MobileGuard,代碼行數:22,代碼來源:GpsTraceService.java

示例12: getDistanceToUser

import android.location.Criteria; //導入方法依賴的package包/類
private Float getDistanceToUser(User u) {
    LocationManager locationManager = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_MEDIUM);
    criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
    String locationProvider = locationManager.getBestProvider(criteria, false);
    Boolean hasLocationPermission = this.hasLocationPermission();
    if (hasLocationPermission && locationProvider != null) {
        Location myLocation = locationManager.getLastKnownLocation(locationProvider);
        Location userLocation = new Location("");
        if (u.location.getValid()) {
            userLocation.setLatitude(u.location.getLatitude());
            userLocation.setLongitude(u.location.getLongitude());
        } else {
            return null;
        }

        if (myLocation != null) {
            return myLocation.distanceTo(userLocation);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
開發者ID:BandUp,項目名稱:band-up-android,代碼行數:27,代碼來源:UserItemFragment.java

示例13: startLocationUpdates

import android.location.Criteria; //導入方法依賴的package包/類
protected void startLocationUpdates() {

        if(ActivityCompat.checkSelfPermission(Activity_Main.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                ActivityCompat.checkSelfPermission(Activity_Main.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(Activity_Main.this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST);
            return;
        }
        if (locationManager != null) {
            final int minTime = 10*1000;
            final int minDistance = 0;
            final Criteria criteria = new Criteria();
            String provider;
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            provider = locationManager.getBestProvider(criteria, true);
            locationManager.requestLocationUpdates(provider, minTime, minDistance, listener);
            locationUpdatesRunning = true;
        }
        setToast(getResources().getString(R.string.location_updated_started), 0);
    }
 
開發者ID:derqurps,項目名稱:noefinderlein,代碼行數:21,代碼來源:Activity_Main.java

示例14: makeNativeCriteria

import android.location.Criteria; //導入方法依賴的package包/類
private static Criteria makeNativeCriteria(LocationRequest request) {
    Criteria criteria = new Criteria();
    switch (request.getPriority()) {
        case LocationRequest.PRIORITY_HIGH_ACCURACY:
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            criteria.setPowerRequirement(Criteria.POWER_HIGH);
            break;
        case LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY:
        default:
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
            break;
        case LocationRequest.PRIORITY_NO_POWER:
        case LocationRequest.PRIORITY_LOW_POWER:
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setPowerRequirement(Criteria.POWER_LOW);
    }
    return criteria;
}
 
開發者ID:microg,項目名稱:android_external_GmsLib,代碼行數:20,代碼來源:NativeLocationClientImpl.java

示例15: GetLastKnownLocation

import android.location.Criteria; //導入方法依賴的package包/類
public static Location GetLastKnownLocation(Context context) {
    // Get location manager
    LocationManager locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);

    // Create location criteria
    Criteria criteria = new Criteria();

    // Set fine accuracy
    criteria.setAccuracy(criteria.ACCURACY_FINE);

    // Get best provider
    String bestProvider = locationManager.getBestProvider(criteria, false);

    // No provider?
    if (bestProvider == null) {
        // Return null
        return null;
    }

    // Return last location
    return locationManager.getLastKnownLocation(bestProvider);
}
 
開發者ID:eladnava,項目名稱:redalert-android,代碼行數:23,代碼來源:LocationLogic.java


注:本文中的android.location.Criteria.setAccuracy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。