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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:37:59+00:00 2026-05-26T21:37:59+00:00

My first location using Core Location is almost always invalid. My code is as

  • 0

My first location using Core Location is almost always invalid.

My code is as follows:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{ 
    //for saving the data ACCURATELY for calculations
    // make sure the coordinates are valid
    if ([self isValidLocation:newLocation withOldLocation:oldLocation])
    {         
        mDistance = [newLocation distanceFromLocation:oldLocation];

        [[NSNotificationCenter defaultCenter]postNotificationName:@"locationUpdated" object:nil];
    }
}

As you can see it checks to see if it is a valid location with isValidLocation. That code is here:

- (BOOL)isValidLocation:(CLLocation *)newLocation
        withOldLocation:(CLLocation *)oldLocation
{    
    // Throw away first point
    if (isFirstPoint)
    {
        NSLog(@"First point thrown away.");
        isFirstPoint = NO; //subsequent updates will NOT be the first point
        return NO;
    }
    // Filter out nil locations
    if (!newLocation){
        NSLog(@"New location invalid");
        return NO;
    }
    if (!oldLocation)
    {
        NSLog(@"Old location invalid");
        return NO;
    }
    // Filter out points by invalid accuracy
    if (newLocation.horizontalAccuracy < 0)
    {
        return NO;
    }
    // Filter out points that are out of order
    NSTimeInterval secondsSinceLastPoint = [newLocation.timestamp 
                                            timeIntervalSinceDate:oldLocation.timestamp];
    if (secondsSinceLastPoint < 0){
        return NO;
    }
    // Filter out points created before the manager was initialized
    NSTimeInterval secondsSinceManagerStarted = [newLocation.timestamp 
                                                    timeIntervalSinceDate:locationManagerStartDate];
    if (secondsSinceManagerStarted < 0){
        return NO;
    }
    // If the distance is negative
    if ([newLocation distanceFromLocation:oldLocation] < 0)
    {
        return NO;
    }
    if(newLocation.speed < 0) 
    {
        return NO;
    }
    // GIANT ELSE: The newLocation is good to use
    return YES;
} 

Even after checking all of that, my first point is always invalid. For example, I went from work to home, and turned on my location manager at home, yet my first coordinate was from my office at work. How can I fix this?

Here is what happens when I get an invalid first point:
enter image description here

  • 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-26T21:37:59+00:00Added an answer on May 26, 2026 at 9:37 pm

    It really depends on your use case. Core Location often returns the device’s last known position in order to give you a result as quickly as possible. This location is passed to you before the device has finished acquiring a new location. The last known position can be several kilometers off your current position.

    Depending on the type of your app, this might be a totally negligible difference (e.g. if an app just wants to locate the country a user is in) or it might represent an inacceptable error. Core Location can’t tell.

    It’s important for you to decide how to deal with this behavior. Always throwing the first reported location away might not be the best strategy. You might want to store the time when you call startUpdatingLocation and only throw the first reported location away if the system passes it to you within a very brief period of time (say, 1/10th of a second) that makes it likely to be a cached location. Also, the location’s timestamp property might be helpful in judging how (in)accurate the reported location can be.

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

Sidebar

Related Questions

I'm using Core Plot 0.9 in my first iPad project. I need to create
I still have problem with fetching first location on android. I am using Criteria
In my application first i am finding the current location using corelocation framework, and
First, let's get the security considerations out of the way. I'm using simple authentication
First off, I am using Windows XP. I have multiple hard drives and it
First off: I'm using a rather obscure implementation of javascript embedded as a scripting
This might be my lack of understanding of the call stack when using Core
Couldn't the diamond problem be resolved just by using the first inherited declaration found?
I need to perform several copy commands on a remote location (using ssh cp
I want to get location using GPS only. I don't want to use internet

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.