cannot obtain current geographic location in android
<p>i have to make an android application in which i need to find the users current location and then obtain a bunch of lat and longs from a database. After this i need to find the distance between the users current location and the lat ,longs.... and for all those distances which are less than 200km i need to add them to a list.</p>

<p><strong>PROBLEM</strong>:
 i am not able to find the current user location and i always obtain 0,0. I have tested the same on an emulator by passing the co-ordinates using DDMS. I have also tried the same on an actual device still i receive 0,0 as the lat, long. Also the distance being calculated is incorrect. </p>

<p>Here is my code:</p>

<pre><code>    LocationManager lm;
LocationListener ll;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.nearactivity);
    mHandler= new Handler();
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    ll = new mylocationlistener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
    showProgress();
}

private void showProgress() {
    pd = new ProgressDialog(NearActivity.this);
    pd.setTitle("Nautic-Dates");
    pd.setMessage("Loading");
    pd.show();
    GetLocations gl = new GetLocations();
    gl.execute();
    try {
        setListAdapter(new CustomeAdapter(gl.get()));
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    pd.dismiss();
}

public class GetLocations extends AsyncTask&lt;Void, Void, ArrayList&lt;String&gt;&gt; {

    @Override
    protected ArrayList&lt;String&gt; doInBackground(Void... arg0) {
        HandleDatabase hb = new HandleDatabase();
        String locations[] = hb.getLocationsFromDatabase();
        ArrayList&lt;String&gt; nearlocations = new ArrayList&lt;String&gt;();
        CustomGeoCoder cg = new CustomGeoCoder();
        for (int i = 0; i &lt; locations.length; i++) {
            String details[] = locations[i].split("--");
            if (details[0].trim().equals("")
                    || details[1].trim().equals("")||details[0].trim().equals("null")
                    || details[1].trim().equals("null")) {
                continue;
            } else {
                float distance = cg.checkLocation(details[0], details[1]);
                if (distance&lt;RADIUS) {
                    nearlocations.add(locations[i]+"--"+distance);
                }
            }
        }
        return  nearlocations;
    }

}

public class CustomGeoCoder {


    public float checkLocation(String string, String string2) {
        Location locationA = new Location("pointA");

        Log.i("current loc", "lat " + lat + " lng " + lng);
        Log.i("checklocation loc", "lat " + string + " lng " + string2);
        locationA.setLatitude(lat);
        locationA.setLongitude(lng);

        Location locationB = new Location("pointB");

        try {
            locationB.setLatitude(Double.parseDouble(string));
        } catch (NumberFormatException e) {
            try {
                locationB.setLatitude(Float.parseFloat(string));
            } catch (NumberFormatException e1) {
                try {
                    locationB.setLatitude(Integer.parseInt(string));
                } catch (NumberFormatException e2) {
                    e2.printStackTrace();
                    return RADIUS+1;
                }

            }
        }
        try {
            locationB.setLongitude(Double.parseDouble(string2));
        } catch (NumberFormatException e) {
            try {
                locationB.setLongitude(Float.parseFloat(string2));
            } catch (NumberFormatException e1) {
                try {
                    locationB.setLongitude(Integer.parseInt(string2));
                } catch (NumberFormatException e2) {
                    e2.printStackTrace();
                    return RADIUS+1;
                }
            }
        }

        float distance = locationA.distanceTo(locationB);

//this code is returning wrong values.
        return distance/1000;
//          Log.i("distance", "" + distance);
//          if (distance / 1000 &gt; RADIUS)
//              return false;
//          else
//              return true;
    }

}

private class mylocationlistener implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {
            Log.d("LOCATION CHANGED", location.getLatitude() + "");
            Log.d("LOCATION CHANGED", location.getLongitude() + "");
            lat = location.getLatitude();
            lng = location.getLongitude();
            Toast.makeText(NearActivity.this,"lng="+lng+" lat="+lat, Toast.LENGTH_SHORT);
            showProgress();
        }
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}
</code></pre>

<p>i am not able to understand what is going wrong?</p>

<p>thank you in advance for your help.</p>
