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 789857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:35:27+00:00 2026-05-14T21:35:27+00:00

I have a few questions (so far) with the the LocationManager on Android and

  • 0

I have a few questions (so far) with the the LocationManager on Android and GPS in general.. Feel free to answer any number of the questions below, and I appreciate your help in advance! (I noticed this stuff doesn’t appear to be documented very well, so hopefully these questions will help others out too!)

1) I am using the following code, but I think there may be extra fluff in here that I do not need. Can you tell me if I can delete any of this?

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);       
LocationListener locationListener = new MyLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); 
LocationProvider locationProvider = lm.getProvider("gps");
Location currentLocation = lm.getLastKnownLocation(locationProvider.getName());

2) Is there a way to hold off on the last step (accessing “getLastKnownLocation” until after I am sure I have a GPS lock? What happens if this is called and GPS is still looking for signal?

3) MOST importantly, I want to ensure I have a GPS lock before I proceed to my next method, so is there a way to check to see if GPS is locked on and getLastKnownLocation is up to date?

4) Is there a way to ‘shut down’ the GPS listener once it does receive a lock and getLastKnownLocation is updated? I don’t see a need to keep this running for my application once I have obtained a lock..

5) Can you please confirm my assumption that “getLastKnownLocation” is updated frequently as the receiver moves?

6) In my code, I also have a class called “MyLocationListener” (code below) that I honestly just took from another example.. Is this actually needed? I assume this updates my location manager whenever the location changes, but it sure doesn’t appear that there is much to the class itself!

private class MyLocationListener implements LocationListener 
    {
        @Override
        public void onLocationChanged(Location loc) {
            if (loc != null) {
                //Toast.makeText(getBaseContext(),   "Location changed : Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show();
            }
        }

        @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
        }

    }     
  • 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-05-14T21:35:27+00:00Added an answer on May 14, 2026 at 9:35 pm
    1. Lines 4-5 seem to be doing you no good. Also, LocationManager.GPS_PROVIDER is "gps", so please just use LocationManager.GPS_PROVIDER.

    For the following answers, I am assuming that by “GPS lock” you mean “GPS fix”.

    1. “Is there a way to hold off on the last step (accessing “getLastKnownLocation” until after I am sure I have a GPS lock?” — sure, by not calling the method. “What happens if this is called and GPS is still looking for signal?” — it returns null.

    2. “MOST importantly, I want to ensure I have a GPS lock before I proceed to my next method” — that is not possible. “so is there a way to check to see if GPS is locked on and getLastKnownLocation is up to date?” — if getLastKnownLocation() returns null, you do not have a fix.

    3. Unregister your LocationListener via removeUpdates().

    4. Yes, your assumption is correct, at least for some definition of “frequently”.

    5. Yes, you need a LocationListener instance to use requestLocationUpdates(). More importantly, when you get called with onLocationChanged() for the first time, that means you got your first fix. Presumably, for how you appear to want to use the code, this is where you would process the fix, then remove the LocationListener per #4 above.

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

Sidebar

Related Questions

I have few questions. As far as I know, every request to a container
I have a few questions connected to Android In-App Billing: Is it possible to
I have few questions about handling large bitmaps, I couldn't find answer on the
I have a few questions regarding android market(Google play). How can I list my
I have few questions about using lock to protect my shared data structure. I
I have few questions, I want to show the alert window on my Update
I have a few questions about Xcode and interaction with GCC 4.2.1: It doesn't
I have a few questions about this after reading the iPhone documentation on it:
I have a few questions related to Windows processes in kernel and usermode. If
I have a few questions relating to setjmp/longjmp usage - What is the use

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.