1

The problem I am facing is that it always returns 0.0 for latitude and longitude. and addresses is null. I have turned on the GPS settings in the phone and set all the permissions

if (gps.isGPSEnabled) {
    progressDialog.setMessage("Loading...");
    progressDialog.show();

    double latitude = gps.getLatitude(); 
    double longitude = gps.getLongitude(); // returns longitude

    Geocoder gcd = new Geocoder(context);
    List<Address> addresses = null;
    try {
        addresses = gcd.getFromLocation(latitude,longitude,1);
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (addresses.size() > 0) {
        service.refreshWeather(addresses.get(0).getLocality().toString());
    } else {

    }
} else {
    gps.showSettingsAlert();
}
j2ko
  • 2,479
  • 1
  • 16
  • 29
  • Where did `gps` come from? – CommonsWare Jun 03 '17 at 21:00
  • What Android OS version do you have? – j2ko Jun 03 '17 at 22:58
  • I assert that 0.0 means here, the `gps` have fields like latitude and longitude to store result of `getLastKnownLocation` method. And again i assert that `getLastKnownLocation` returned null, fields didn't set and above getter methods returned default values of fields (0.0) – blackkara Jun 04 '17 at 00:22

0 Answers0