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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:48:34+00:00 2026-06-01T05:48:34+00:00

This is the code snippet that the developer site has provided for getting a

  • 0

This is the code snippet that the developer site has provided for getting a better fix. I have a doubt in this. In this implementation, the function checks if it is significantly newer, then it returns true in the very beginning itself. But what if the newer fix is from the network provider and if it is less accurate. Still it returns true, which should not be the case. Is this a bug or is my understanding wrong ?

Link: http://developer.android.com/guide/topics/location/obtaining-user-location.html

protected boolean isBetterLocation(Location location, Location currentBestLocation) {


if (currentBestLocation == null) {
    // A new location is always better than no location
    return true;
}

// Check whether the new location fix is newer or older
long timeDelta = location.getTime() - currentBestLocation.getTime();
boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
boolean isNewer = timeDelta > 0;

// If it's been more than two minutes since the current location, use the new location
// because the user has likely moved
if (isSignificantlyNewer) {
    return true;
// If the new location is more than two minutes older, it must be worse
} else if (isSignificantlyOlder) {
    return false;
}

// Check whether the new location fix is more or less accurate
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
boolean isLessAccurate = accuracyDelta > 0;
boolean isMoreAccurate = accuracyDelta < 0;
boolean isSignificantlyLessAccurate = accuracyDelta > 200;

// Check if the old and new location are from the same provider
boolean isFromSameProvider = isSameProvider(location.getProvider(),
        currentBestLocation.getProvider());

// Determine location quality using a combination of timeliness and accuracy
if (isMoreAccurate) {
    return true;
} else if (isNewer && !isLessAccurate) {
    return true;
} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
    return true;
}
return false;

}

  • 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-01T05:48:36+00:00Added an answer on June 1, 2026 at 5:48 am

    Significantly newer means location has changed a lot and thus even a network location fix is more precise than an older gps location fix. So yes that makes sense.

    Nevertheless, I think your idea to give priority to the finest location source is good, you should implement it and maybe maintain two different fixes from the two different sources.

    It would have been nice to provide a link to the tutorial you got inspired by.

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

Sidebar

Related Questions

I have this code snippet inside a function that checks if an object exists
In this link: http://css-tricks.com/snippets/jquery/jquery-plugin-template/ it has a line of code that says // Add
Take this code snippet for example: window.location.href = 'mysite.htm#images'; Already being on the site
VS 2008 I have this code snippet I found on a VB website. But
I have this code snippet: <div id=div1> </div> <div id=div2> <h3>This is the content</h3>
One of my fellow developer has a code similar to the following snippet class
I have the following code snippet which uses'event' My fellow developers argue that the
This code snippet is from C# in Depth static bool AreReferencesEqual<T>(T first, T second)
A friend gave me this code snippet in Clojure (defn sum [coll acc] (if
I am using this code snippet to add KeyDown event handler to any element

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.