I recently added my application to the collect feature the latitude and longitude points of the GPS on which the device is located.
I've added lines to AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
I created an Activity that implements LocationListener
public class MinhaClasse extends FragmentActivity implements LocationListener {
and the OnCreate Event instantiated the classes that will be used.
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, this );
if (location != null) {
onLocationChanged(location);
} else {
.... "Localização não disponível"
}
@Override
public void onLocationChanged(Location location) {
float lat = (float) (location.getLatitude());
float lng = (float) (location.getLongitude());
}
In this way it is working, it happens that the point returned is not always the best. Most of the time this point is 50 meters away from the device and I do not see how to update it. When this application was running on a Windows Mobile device I read a 100 points and then took an average of those points and the resulting position was accurate in the case of centimeters.
How can I 'force' you to update the reading as many times as I want?