Hey guys

i am trying to get the user's current location through GPS but i always get 
the previous LastKnownLocation.

I am trying this since last 4 to 5 hours but i didn't find the refereched 
current location.

can anybody plz tell me how can i remove a listener of the 
lastknownlocation.

i had also try this code : locationManager.removeUpdates(locationListener);
but i didn't get success.

=======================================================================================================
 
this is my code : 
=======================================================================================================
                            Location location=null;
                            double lat1,lng1;
    LocationManager mlocManager = 
(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    LocationListener mlocListener = new MyLocationListener();
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, 
mlocListener);
    location = 
mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    
   
     mlocManager.removeUpdates(mlocListener);
     Toast.makeText(this, "previous update is removed", 
Toast.LENGTH_LONG).show();
     mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, 
mlocListener);
     location = 
mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
     
     try
    {
     lat1=location.getLatitude();
     lng1=location.getLongitude();
     Toast.makeText(this, "lat : "+lat1+", lng : "+lng1, 
Toast.LENGTH_LONG).show();
    }
    catch(Exception e)
    {
     e.printStackTrace();
     Toast.makeText(getApplicationContext(), 
                                                 "Your current location is 
temporarily unavailable - Try Again!", Toast.LENGTH_LONG).show();
    }


=======================================================================================================
 
public class MyLocationListener implements LocationListener
{
    @Override
    public void onLocationChanged(Location loc)
    {
    }

    @Override
    public void onProviderDisabled(String provider)
    {

    }

    @Override
    public void onProviderEnabled(String provider)
    {

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras)
    {
    }
 }
=======================================================================================================

Please help me what can i do? i didn't understand... 
    

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to