本文整理匯總了Java中android.location.Criteria類的典型用法代碼示例。如果您正苦於以下問題:Java Criteria類的具體用法?Java Criteria怎麽用?Java Criteria使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Criteria類屬於android.location包,在下文中一共展示了Criteria類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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) {
}
}
示例2: 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;
}
示例3: 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 "";
}
示例4: 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 "";
}
示例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;
}
示例6: LocationSensor
import android.location.Criteria; //導入依賴的package包/類
/**
* Creates a new LocationSensor component.
*
* @param container ignored (because this is a non-visible component)
*/
public LocationSensor(ComponentContainer container) {
super(container.$form());
handler = new Handler();
// Set up listener
form.registerForOnResume(this);
form.registerForOnStop(this);
// Initialize sensor properties (60 seconds; 5 meters)
timeInterval = 60000;
distanceInterval = 5;
// Initialize location-related fields
Context context = container.$context();
geocoder = new Geocoder(context);
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
locationCriteria = new Criteria();
myLocationListener = new MyLocationListener();
allProviders = new ArrayList<String>();
// Do some initialization depending on the initial enabled state
Enabled(enabled);
}
示例7: getLocation
import android.location.Criteria; //導入依賴的package包/類
@Override
public Location getLocation(Context context) {
if(config != null && config.getBooleanProperty(SocializeConfig.SOCIALIZE_LOCATION_ENABLED, true)) {
if(location == null) {
if(appUtils.hasPermission(context, "android.permission.ACCESS_FINE_LOCATION")) {
requestLocation(context, Criteria.ACCURACY_FINE);
}
else if(appUtils.hasPermission(context, "android.permission.ACCESS_COARSE_LOCATION")) {
requestLocation(context, Criteria.ACCURACY_COARSE);
}
}
else if(logger != null && logger.isDebugEnabled()) {
logger.debug("LocationProvider got location");
}
}
return location;
}
示例8: 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);
}
示例9: getLatestLocation
import android.location.Criteria; //導入依賴的package包/類
private Location getLatestLocation() {
// Enable MyLocation Layer of Google Map
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), "No permission to get location information.", Toast.LENGTH_LONG).show();
return null;
}
// Get LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Create a criteria object to retrieve provider
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
// Get the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
// Get Current Location
return locationManager.getLastKnownLocation(provider);
}
示例10: setupLocationListener
import android.location.Criteria; //導入依賴的package包/類
@SuppressLint("MissingPermission")
private void setupLocationListener() {
locationListener = new LocationListener();
locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
TIME_TO_UPDATE = Integer.parseInt(sharedPreferences.getString("sync_frequency", "60")) * 1000;
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);
locationManager.requestLocationUpdates(bestProvider, TIME_TO_UPDATE, DISTANCE_TO_CHANGE, locationListener);
}
示例11: 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);
}
示例12: onCreate
import android.location.Criteria; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLat = (TextView) findViewById(R.id.txtLat);
txtLong = (TextView) findViewById(R.id.txtLong);
txtSource = (TextView) findViewById(R.id.txtSource);
// Initialize locationManager
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
// Initialize the location
if (location != null) {
txtSource.setText("Source = " + provider);
onLocationChanged(location);
}
}
示例13: addProvider
import android.location.Criteria; //導入依賴的package包/類
/**
* Registers a test provider with the given name on the location manager.
*
* @param providerName
* - the name of the test provider to be registered
*/
private void addProvider(String providerName) {
try {
locationManager.addTestProvider(providerName, false, // does not require network
false, // does not require satellite
false, // does not require cell
false, // no monetary cost
true, // supports altitude
true, // supports bearing
true, // supports speed
Criteria.POWER_LOW,
Criteria.ACCURACY_HIGH);
} catch (IllegalArgumentException e) {
// guarding from registering a test provider that is already registered
}
locationManager.setTestProviderEnabled(providerName, true);
}
示例14: 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);
}
示例15: 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);
}