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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:01:36+00:00 2026-05-26T13:01:36+00:00

I am using the CoreLocation framework to get my speed and distance to calculate

  • 0

I am using the CoreLocation framework to get my speed and distance to calculate average speed.

On the first update that CoreLocation sends out, it shows negative values for both speed and distance traveled. How can I fix this?

Speed is locationController.locationManager.location.speed where locationController holds my CoreLocation delegate. Distance is calculated by taking the old location and the new location and calculating distance.

//Distance
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    // make sure the old and new coordinates are different
    if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
        (oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
    {         
        mDistance = [newLocation distanceFromLocation:oldLocation];
    }
}
  • 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-26T13:01:37+00:00Added an answer on May 26, 2026 at 1:01 pm

    The data returned by Core Location may be invalid for a number of reasons. Before you use the data, run this method to see if it is valid.

    // From http://troybrant.net/blog/2010/02/detecting-bad-corelocation-data/
    - (BOOL)isValidLocation:(CLLocation *)newLocation
            withOldLocation:(CLLocation *)oldLocation 
    {
        // filter out nil locations
        if (!newLocation){
            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;
        }
        // newLocation is good to use
        return YES;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to calculate the average speed of the user using Core Location,
In my application first i am finding the current location using corelocation framework, and
I have many coordinates that I am plotting using a MKMapOverlay and CoreLocation and
HI , i m using CoreLocation Framework and getting the location. in Simulator it
I have create a program to find out my current location using IOS corelocation
How can I calculate speed using Core Location? I would like to use GPS
Hello I am using CoreLocation to get latitude and longitude in my map application
I am trying to find the location of user using corelocation framework in my
I am using the ALAssets framework to access the Photo Library. The first time
I'm currently using CoreLocation + CLLocationManager in order to compare a users current location

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.