0

I am making an app in which i have to get altitude of device and my code is as follows:

public class MyLocationListener implements LocationListener
 {
    public void onLocationChanged(Location loc)
    {
        try 
        {
        System.out.println("............ ..............................Location changedin 11");
        latitude = loc.getLatitude();

        longitude = loc.getLongitude();
        altitude=loc.getAltitude();
        System.out.println("alt"+altitude);
              System.out.println("latitude123 "+latitude);
        System.out.println("longi: "+longitude);
        System.out.println("longitude curr_lon");
        loc.getAccuracy();
        System.out.println("loc"+loc.getAccuracy());

        latitudee=(TextView)findViewById(R.id.latitudee);
        latitudee.setText(""+latitude);

        longitudee=(TextView)findViewById(R.id.longitudee);
        longitudee.setText(""+longitude);

        accuracyy=(TextView)findViewById(R.id.accuracyy);
        accuracyy.setText(""+loc.getAccuracy());

         System.out.println("alti:"+altitude); // alti is coming out to be 0.0
                    }
        catch (Exception e1) {
            e1.printStackTrace();
        }

        }

    @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

    }
    }

The value of altitude is coming to be0.0 .Any help will be appreciated.

  • Have you checked with `loc.hasAltitude()` if the `LocationProvider` actually supplies any altitude info? If it's cell-based location, it probably won't. – Philipp Reichart Dec 22 '11 at 13:55
  • Philipp Reichart , i tried that but it didnt worked –  Dec 23 '11 at 05:24
  • How did it not work? If `hasAltitude()` is `false`, `getAltitude()` will rightfully return zero. – Philipp Reichart Dec 23 '11 at 10:21
  • Philipp Reichart, it is always giving false value.. –  Dec 26 '11 at 05:24
  • You will only get altitude from the gps device. You have bnot showen the source for the setup. the accuracy is not so good even then. – Ifor Jan 03 '12 at 15:44

1 Answers1

0

Wait for more than 1 minute GPS takes some time to take altitude from satellite after one minute it will show altitude.

Ajay
  • 552
  • 2
  • 4
  • 16