Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:05:26+00:00 2026-06-05T20:05:26+00:00

Does anybody know why my getAltitude in the following always returns 0? package com.example.helloandroid;

  • 0

Does anybody know why my getAltitude in the following always returns 0?

package com.example.helloandroid;

import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

public class HelloAndroid extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d("main", "onCreate");
        setupGps();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    LocationListener locationListener;
    LocationManager lm;

    void setupGps() {
        Log.d("gps", "Setting up GPS...");
        locationListener = new MyLocationListener();
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 5,
                locationListener);

        Log.d("gps",
                "GPS supports altitude: "
                        + lm.getProvider(LocationManager.GPS_PROVIDER)
                                .supportsAltitude());
        Log.d("gps", "Finished setting up GPS.");
    }

    static class MyLocationListener implements LocationListener {

        public void onLocationChanged(Location location) {
            Log.d("gps", "onLocationChanged");
            Log.d("gps",
                    "x: " + location.getLongitude() + ", y: "
                            + location.getLatitude() + ", alt.: "
                            + location.getAltitude());
        }

        public void onProviderDisabled(String provider) {
            Log.d("gps", "onProviderDisabled");
        }

        public void onProviderEnabled(String provider) {
            Log.d("gps", "onProviderEnabled");
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.d("gps",
                    "onStatusChanged; new status: " + String.valueOf(status));
        }
    }
}

To test, I issue a geo command with an altitude to the emulator:

[someone@somewhere ~]$ telnet localhost 5554
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
OK
geo fix -121.45356 46.51119 4392
OK

But getAltitude() returns 0:

enter image description here

I have only tried with emulated devices.

Edit

Following up on cheeken’s comment, I verified that Location.hasAltitude() is true. It is. Any other idea?

public void onLocationChanged(Location location) {
    Log.d("gps", "onLocationChanged");
    Log.d("gps", "x: " + location.getLongitude() 
        + ", y: " + location.getLatitude());
    Log.d("gps", "hasAltitude: " + location.hasAltitude() 
        + ", alt.: " + location.getAltitude());
}

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:05:26+00:00Added an answer on June 5, 2026 at 8:05 pm

    It seems like a lot of people are having similar issues with this and has even been reported as a possible bug. I wouldn’t be surprised if the emulator simply doesn’t support it at this time. You’ll probably have to work with a real device.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know the case when [NSFileVersion unresolvedConflictVersionsOfItemAtURL:] returns more then 1 versions?
Does anybody know sources in internet where described how to build an android application
Does anybody know how to determine whether a certain git commit, for example this
Does anybody know whether this can be achieved in jQuery. Target/addClass to the last
Does anybody know what the default font family is in a table row element?
Does anybody know how i would go about forcing a panel to be square.
Does anybody know how to automagically get xpath with keys when using dom4j elements?
does anybody know what are for PG and GG variables here: module sum(S, Cout,PG,GG,A,B,Cin);
Does anybody know the state of half precision floating point support in OpenCL as
Does anybody know whether there's a way of finding out whether a particular file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.