I am developing an android app based on GPS location navigation for finding user current location. I am using GPS_PROVIDER I dont want to use any other provider like PASSIVE_PROVIDER or NETWORK_PROVIDER currently my code is working and it gives me the coordinates accurately but when I exit from application and again start the application it gives me slightly different coordinates from the old ones while I am on same place and same position.
To find GPS coordinates I used following code.
LocationManager mlocManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
MyLocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, mlocListener);
and my Listener class is
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " + "Latitud = "
+ loc.getLatitude() + "Longitud = " + loc.getLongitude();
TextView txtgps = (TextView) findViewById(R.id.text_GPS_Coordinates);
txtgps.setText(Text);
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
.show();
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(getApplicationContext(), "Disable",
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(getApplicationContext(), "Enable",
Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
I define permission in AndroidManifest is :
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Please tell me the method which gives me the accurate and reliable coordinates and if possible, please explain your code.