首先获取LocationManager、Location及Criteria
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager) getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria,
true);
Location location = locationManager
.getLastKnownLocation(provider);
Criteria 类介绍:
Criteria是“精确度”的意思,Criteria类提供若干个查询条件:
(1) public void setAccuracy( int accuracy)
位置解析的精度,高或低