Get Gps Co-Ordinates in android
<p>I am unable to get gps programmatically. Many examples are given in stack overflow but still i am getting null value. What i want to do, i have a button on clicking the button i want to get gps coordinate. Here is my code in order to get gps cordinate.</p>

<p>on button click i have just call the getlocation()</p>

<pre><code>private LocationManager lm;
private LocationListener locationListener;

public void getlocation()
{       

    lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); 
    locationListener = new MyLocationListener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);

}

 class MyLocationListener implements LocationListener 
 {
     String a;
     String b;
     String c;

    public void onLocationChanged(Location loc) 
    {
        if (loc != null) {

            LAT = loc.getLatitude();
            LONG = loc.getLongitude();  
            a=Double.toString(LAT);
            b=Double.toString(LONG);
            c="-----LAT is:"+a+"  "+"LONG is--------:"+b;
            System.out.println(c);
            //Toast.makeText(context, "Your location is:"+c, Toast.LENGTH_LONG).show();




        }
    }

    @Override
    public void onProviderDisabled(String provider) 
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider)
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) 
    {
        // TODO Auto-generated method stub

    }

}
</code></pre>

<p>Can any body help? what's wrong here???</p>
