user881928
user881928

Reputation:

android:implement altitude of device

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.

Upvotes: 0

Views: 434

Answers (1)

Ajay
Ajay

Reputation: 542

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

Upvotes: 0

Related Questions