title: Core Location First Point Invalid
body: <p>My first location using <code>Core Location</code> is almost always invalid.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>- (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];
      }
  }
  </code></pre>
  
  <p>As you can see it checks to see if it is a valid location with <code>isValidLocation</code>. That code is here:</p>
  
  <pre><code>- (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 &lt; 0)
      {
          return NO;
      }
      // Filter out points that are out of order
      NSTimeInterval secondsSinceLastPoint = [newLocation.timestamp 
                                              timeIntervalSinceDate:oldLocation.timestamp];
      if (secondsSinceLastPoint &lt; 0){
          return NO;
      }
      // Filter out points created before the manager was initialized
      NSTimeInterval secondsSinceManagerStarted = [newLocation.timestamp 
                                                      timeIntervalSinceDate:locationManagerStartDate];
      if (secondsSinceManagerStarted &lt; 0){
          return NO;
      }
      // If the distance is negative
      if ([newLocation distanceFromLocation:oldLocation] &lt; 0)
      {
          return NO;
      }
      if(newLocation.speed &lt; 0) 
      {
          return NO;
      }
      // GIANT ELSE: The newLocation is good to use
      return YES;
  } 
  </code></pre>
  
  <p>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?</p>
  
  <p>Here is what happens when I get an invalid first point:
  <img src="https://i.stack.imgur.com/5hDck.png" alt="enter image description here"></p>