9
I recently added my application to collect functionality the latitute and longitude points of the GPS at which the device is located.
To do so I added the 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 in the Oncreate Event I instituted 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());
}
This way this working, it happens that the returned point is not always the best. Most of the time that point is 50 meters away from the device and I don’t see how to update it. When this application ran on a device with Windows Mobile I read about 100 points and then took an average of those points and the resulting position was accurate in the centimeter range.
How can I 'force' you to refresh your reading as many times as I want?
Note that I passed 0.0 for the update to be maximum, but this does not occur. Updates occur, but I did not understand how. I’ve stayed in the same place and they occurred and I moved and they didn’t occur.
– Reginaldo Rigo
Yes, I understand the question of the reception and the number of satelites. It turns out that even in favorable conditions the point is inaccurate. The technique of reading several times and taking an average had a good effect on Windows Mobile devices.
– Reginaldo Rigo
Look how strange. I changed the parameters and put a minTime equal to 100. On the way back from lunch, I run my application and the coordinate he gives me is that of the restaurant, 200 meters away from where I am now.
– Reginaldo Rigo
Seeing that call to
onLocationChanged(location);
in theonCreate()
it is possible that this is theLastKnownLocation
. The fact of puttingminTime igual a 100
does not mean that the method is called 100 in 100 milliseconds. GPS may not have been able to get a new location between the restaurant’s route to where it is now.– ramaral
Now. Using the Locationservices Googleapiclient API calls to updates can be made quite easily and responses are much more accurate. Although I am in a covered area the point 'falls' exactly where I am. Thanks. Thanks even.
– Reginaldo Rigo