我正在使用以下代码来检测用户位置, 它的工作精度为20,而我又变长了, 但有时发生率超过70,而larLong不正确, 因此有可能对其进行改进以获得更好的结果 谢谢
public Location getLocation() {
locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(true);
criteria.setSpeedRequired(true);
criteria.setCostAllowed(true);
criteria.setBearingRequired(true);
//API level 9 and up
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
criteria.setBearingAccuracy(Criteria.ACCURACY_HIGH);
criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);
String provider = locationManager.getBestProvider(criteria,true);
if(provider!=null && !provider.equals("")){
Log.e("provider",provider);
locationManager.requestLocationUpdates(provider,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,this);
}else {
locationManager.requestLocationUpdates(
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,criteria, this,null);
}
Location networkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Location gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (networkLocation != null) {
Log.e("location","networkLocation");
location=networkLocation;
latitude = location.getLatitude();
longitude = location.getLongitude();
accuracy = location.getAccuracy();
} else if (gpsLocation != null) {
Log.e("location","gpsLocation");
location=gpsLocation;
latitude = location.getLatitude();
longitude = location.getLongitude();
accuracy = location.getAccuracy();
}else {
this.canGetLocation=false;
}
stopUsingGPS();
return location;
}