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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:35:03+00:00 2026-06-10T06:35:03+00:00

In the code below getLastKnownLocation() always returns null on a device, even when I

  • 0

In the code below getLastKnownLocation() always returns null on a device, even when I am getting Provide = internet. It was working fine but know it’s returning a null value. I am using a Galaxy Tab version 2.2.

public void find_Location(Context con) {
  Log.d("Find Location", "in find_location");
  this.con=con;
  String location_context = Context.LOCATION_SERVICE;
  LocationManager locationManager =
    (LocationManager)con.getSystemService(location_context);
  List<String> providers = locationManager.getProviders(true);
  for (String provider : providers) {
    locationManager.requestLocationUpdates(provider, 1000, 0,new LocationListener() {
      public void onLocationChanged(Location location) {}
      public void onProviderDisabled(String provider){}
      public void onProviderEnabled(String provider){}
      public void onStatusChanged(String provider, int status,Bundle  extras){}
    });
    Location location = locationManager.getLastKnownLocation(provider);
    if (location != null) {
      lat = location.getLatitude();
      lng = location.getLongitude();
      Geocoder geocoder = new Geocoder(AdvanceSearch.this,
        Locale.getDefault());List<Address> addresses;
      try {
        addresses = geocoder.getFromLocation(lat,lng,100);
        countryname=addresses.get(0).getCountryName();
        eexit e = new eexit();
        statename= addresses.get(0).getAdminArea();
        cityname=addresses.get(0).getLocality();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
}

Thanks in advance for your help.

  • 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-10T06:35:05+00:00Added an answer on June 10, 2026 at 6:35 am

    I would focus on this line first. Your requestLocationUpdates has a minDistance set at 0.

    Play around with the minDistance, I think that is where your problem is.

    locationManager.requestLocationUpdates(provider, 1000, 15, new LocationListener() {
    

    Edit:

    In addition I would add a Log to your LocationListener methods. Doing this has helped me quite a bit.

    Here is an example of my early LocationListener script:

    public LocationListener jLocListener = new LocationListener() {
        //class findMe implements LocationListener {
        public void onLocationChanged(Location location) {
            try {
                lat = location.getLatitude();
                lon = location.getLongitude();
            } catch (Exception e) {
                Log.e("onLocationChanged", "FAILED: " + e.getMessage());
            }
        }
        public void onProviderDisabled(String provider) {
            Log.i("LocationListener", "onProviderDisabled");
        }
        public void onProviderEnabled(String provider) {
            Log.i("LocationListener", "onProviderEnabled");
        }
        public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.i("LocationListener", "onStatusChanged");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

code below working fine but not in IE6, IE7, below is the code is
Code below returns JavaScript error : TypeError: Response is null Note: it works fine
Code below is working fine and draw a colored triangle equal sides: GLfloat triangle_pos[]
The code below works fine but, in the textbox the decimal value has this
Code below works fine in FF, CH etc. but doesn't get centred in IE.
the code below is working, but I want to make sure it's correct .
the code below returns the fields of a given table (Employee), but I need
Code below is working well as long as I have class ClassSameAssembly in same
The code below sets a select menu with UI selectmenu by $('.anyclass').selectmenu(); but the
The code below will validate required fields within currently visible fieldsets, but only if

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.