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

  • Home
  • SEARCH
  • 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 8700773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:14:45+00:00 2026-06-13T02:14:45+00:00

I get location as: LocationManager locationManager; GeoPoint p; locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); boolean gps_enabled

  • 0

I get location as:

    LocationManager locationManager;
                GeoPoint p; 
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);


                boolean gps_enabled = locationManager
                        .isProviderEnabled(LocationManager.GPS_PROVIDER);
                if (gps_enabled) {
                    Location location = locationManager
                            .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                }

However, gps_enabled=true but location =null.
Why can’t get my location? Can you help me?
If i get by NETWORK_PROVIDER is ok.

  • 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-13T02:14:46+00:00Added an answer on June 13, 2026 at 2:14 am

    Well there are a number of things. The GPS could be coming from what’s known as a “cold start” where it doesn’t have any knowledge of where it is. In these cases the last known location is null. You could also be in a location where there is no signal to get a location fix. It could also be a crappy GPS or a crappy GPS driver (cough samsung cough). These things aren’t exact.

    First I would start with this documentation. Location Acquisition Strategies

    Next, let’s evaluate the logic here. Yes the GPS is enabled. However in this context, enabled means that it is enabled for use by applications with the fine location permission. Enabled does not mean it is currently active and acquiring locations. But there is good news! You can make a listener or subscribe to location updates.

    So as others have mentioned, make sure you have the permissions setup in your manifest. I assume you do, or else your app probably crashed and burned with a permission issue on the getLastKnownLocation() call.

    Then for receiving location updates, take a look at the LocationListener class. By implementing this interface you can use locationManager.requestLocationUpdates() to register for location updates from the GPS.

    Using your code (I assume some things, like it’s within an activity and the method being described is invoked on the UI Thread):

    public class MyActivity extends Activity implements LocationListener {
      // The rest of the interface is not really relevant for the example
      public void onProviderDisabled(String provider) { }
      public void onProviderEnabled(String provider) { }
      public void onStatusChanged(String provider, int status, Bundle extras) { }
    
      // When a new location is available from the Location Provider,
      // this method will be called.
      public void onLocationChanged(Location location) {
            // You should do whatever it was that required the location
            doStuffWithLocation(location);
            // AND for the sake of your users' battery stop listening for updates
            (LocationManager) getSystemService(LOCATION_SERVICE).removeUpdates(this);
            // and cleanup any UI views that were informing of the delay
            dismissLoadingSpinner();
      }
    
      // Then in whatever code you have
      public void methodA() {
        LocationManager locationManager;
        GeoPoint p; 
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        boolean gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (gps_enabled) {
          Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
          if (location == null) {
                // When it is null, register for update notifications.
                // run this on the UI Thread if need be
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
                // Since this might take some time you should give the user a sense
                // that progress is being made, i.e. an indeterminate ProgressBar 
                showLoadingSpinner();
          } else {
                // Otherwise just use the location as you were about to
                doStuffWithLocation(location);
          }
        }
        ...
    

    This should run your code as you would expect, and then in the case where the GPS does not have a location, you spin it up and wait until you get a location. Once that occurs you shut it off and use it as you were planning to. This is sort of a naive approach, but you should be able to use it as a simple basis. A real solution should take into account the cases where there is no chance of getting a location, handling the cases when the location provider is not available or becomes unavailable while you are waiting for a location, and validate the sanity of the location.

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

Sidebar

Related Questions

I'm trying to get my location using it like this: LocationManager myLocationManager = (LocationManager)
I've singled out my problem to a few lines of code lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
I am trying to get the location in my Android app as follows LocationManager
I'm trying to get the user location based on the Network Provider, but the
My problem is tat when i get location from locationManager it sometimes doesn't load
I would like to get location of user, so I have this code: LocationManager
I'm using GPS to get my location but this code shows my location in
I'm Trying to get the user geopoint with this code LocationManager locationManager = (LocationManager)
My getLastKnownLocation is turning up null. I can get the locations I put in
When using a Location Manager to get a Location object containing Latitude and Longitude,

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.