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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:15:12+00:00 2026-06-05T08:15:12+00:00

I’m using the following code in my app, from tutorials etc., to get the

  • 0

I’m using the following code in my app, from tutorials etc., to get the best possible location fix from the GPS (or if GPS not on, network), which I then display in a text field.

crit = new Criteria();
context = Context.LOCATION_SERVICE;
locationManager = (LocationManager) this.getSystemService(context);
crit.setAccuracy(Criteria.ACCURACY_FINE);
crit.setPowerRequirement(Criteria.POWER_LOW);
crit.setAltitudeRequired(false);
crit.setBearingRequired(false);
crit.setSpeedRequired(false);
crit.setCostAllowed(false);
try {
    bestProvider = locationManager.getBestProvider(crit, true);
    loc = locationManager.getLastKnownLocation(bestProvider);
    locationManager.requestLocationUpdates(bestProvider, 0, 0,
            new GeoUpdateHandler());
} catch (java.lang.RuntimeException run) {
    Toast.makeText(getBaseContext(),
    "Waiting for location fix...", Toast.LENGTH_SHORT).show();
}

My problem is moving between locations. I start using my app in Norfolk and get the location OK. The next day, I’m in Cornwall (100’s mile apart) and when I switch on my app (it should have been closed/destroyed by Android in this time), it is still showing me the Norfolk location. I find that if I then exit my app and start it again, it then picks up the new location. I can do this easily, but my users are finding it a real pain.

My assumptions were that if GPS/network is available, then I start the app, the LOC is created from last known location, then locationManager updates instantly (which should update LOC instantly?) using:

public class GeoUpdateHandler implements LocationListener {
  public void onLocationChanged(Location location) {
    loc = location;
  }
  public void onProviderDisabled(String provider) { }
  public void onProviderEnabled(String provider) {  }
  public void onStatusChanged(String provider, int status, Bundle extras) { }
}

Clearly this update isn’t happening.

Can anyone tell me if my code is stupid, or advise on a better way to make sure I’m always dealing with current location? Thanks. Apologies if this is answered, difficult to find in amongst all the posts on locations & requestLocationUpdates tags.

  • 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-05T08:15:13+00:00Added an answer on June 5, 2026 at 8:15 am

    After discussion in chat I suggested the following:

    You need to call requestLocationUpdates() and then show the user a dialog saying something like ‘getting your location’. At some time later, you should get a callback onLocationChanged() with an up-to-date location. At that point you can dismiss the dialog and update the text fields and whatever else you want to show the user. You should also call removeUpdates() once you’ve got an up-to-date location so that you don’t drain the user’s battery.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I am using Paperclip to handle profile photo uploads in my app. They upload
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.