In my application I have to fetch the current location. First it correctly fetches the location. But we are moving from the current location to some other location. It shows the previous address. It is not updating the location. My code is:
locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locListener = new MyLocationListener();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locListener);
location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null)
{
latitude = location.getLatitude();
longitude = location.getLongitude();
}
//My location listener is as follows
public void onLocationChanged(Location loc) {
if (loc != null) {
//Toast.makeText(this.getBaseContext(),
//"Location changed : Lat: " + loc.getLatitude() +
//" Lng: " + loc.getLongitude(),
//Toast.LENGTH_LONG).show();
double lat = loc.getLatitude();
double lon = loc.getLongitude();
}
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
Please find the mistake and when i launch first time it is not working on second time itself it is working....so check this thing also.....