How to get a more accurate gps location?
I have an app that will get the users gps location. The problem is right now it is a bit inaccurate (it shows me in a different building 20-60m off)
here is my code
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String bestProvider = locationManager.getBestProvider(criteria,
false);
LocationListener loc_listener = new LocationListener() {
@Overr开发者_C百科ide
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
};
try {
Looper.prepare();
locationManager.requestLocationUpdates(bestProvider, 0, 0,
loc_listener);
} catch (Exception e) {
e.printStackTrace();
}
Location location = locationManager
.getLastKnownLocation(bestProvider);
I believe I should wait at least one second before sending location.getLatitude() and location.getLongitude() Right now the wait time is almost instant but the accuracy is pretty off. I am using my
Each location update provided by your GPS chip will have an accuracy value. You should consider throwing away ones that are above a threshold.
However, indoors GPS struggles to get a signal, so accuracy will decrease, if it even manages to get a lock at all!
精彩评论