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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:37:32+00:00 2026-05-22T01:37:32+00:00

I am having a map application. When a person travels from current location to

  • 0

I am having a map application. When a person travels from current location to particular location I want to calculate the distance covered by the person, the current speed of the person, average speed of the person.

  • 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-22T01:37:32+00:00Added an answer on May 22, 2026 at 1:37 am

    Use following methods to get distance in miles or kilometers. You have to declare timer in your header file synthesize it.

    //SpeedViewController.h
    #import <UIKit/UIKit.h>
    #import <CoreLocation/CoreLocation.h>
    #import <MobileCoreServices/UTCoreTypes.h>
    
    @interface SpeedViewController : UIViewController <CLLocationManagerDelegate,UINavigationControllerDelegate>
    {
        CLLocationManager *locManager;
        CLLocationSpeed speed;
        NSTimer *timer;
    
        CLLocationSpeed currentSpeed;
        float fltDistanceTravelled; 
    }
    
    @property (nonatomic,retain) NSTimer *timer;
    
    -(float)getDistanceInKm:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
    -(float)getDistanceInMiles:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
    
    @end
    
    //SpeedViewController.h
    #import "SpeedViewController.h"
    #define kRequiredAccuracy 500.0 //meters
    #define kMaxAge 10.0 //seconds
    #define M_PI   3.14159265358979323846264338327950288   /* pi */
    
    
    @implementation SpeedViewController
    
    @synthesize timer;
    - (void)startReadingLocation {
        [locManager startUpdatingLocation];
    }
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        CLLocationManager *locationManager=[[CLLocationManager alloc] init];
        locationManager.delegate=self;
        locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
        [locationManager startUpdatingLocation];
    }
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    
        // Release any cached data, images, etc. that aren't in use.
    }
    
    - (void)viewDidUnload {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
    {
        NSLog(@"new->%d old->%d",(newLocation==NULL),(oldLocation==NULL));
    
        if(newLocation && oldLocation)
        {
            fltDistanceTravelled +=[self getDistanceInKm:newLocation fromLocation:oldLocation];
        }
    }
    
    //this is a wrapper method to fit the required selector signature
    - (void)timeIntervalEnded:(NSTimer*)timer {
        fltDistanceTravelled=0;
        [self startReadingLocation];
    }
    
    
    -(float)getDistanceInKm:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        float lat1,lon1,lat2,lon2;
    
        lat1 = newLocation.coordinate.latitude  * M_PI / 180;
        lon1 = newLocation.coordinate.longitude * M_PI / 180;
    
        lat2 = oldLocation.coordinate.latitude  * M_PI / 180;   
        lon2 = oldLocation.coordinate.longitude * M_PI / 180;
    
        float R = 6371; // km
        float dLat = lat2-lat1;
        float dLon = lon2-lon1; 
    
        float a = sin(dLat/2) * sin(dLat/2) + cos(lat1) * cos(lat2) * sin(dLon/2) * sin(dLon/2); 
        float c = 2 * atan2(sqrt(a), sqrt(1-a)); 
        float d = R * c;
    
        NSLog(@"Kms-->%f",d);
    
        return d;
    }
    
    -(float)getDistanceInMiles:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        float lat1,lon1,lat2,lon2;
    
        lat1 = newLocation.coordinate.latitude  * M_PI / 180;
        lon1 = newLocation.coordinate.longitude * M_PI / 180;
    
        lat2 = oldLocation.coordinate.latitude  * M_PI / 180;   
        lon2 = oldLocation.coordinate.longitude * M_PI / 180;
    
        float R = 3963; // km
        float dLat = lat2-lat1;
        float dLon = lon2-lon1; 
    
        float a = sin(dLat/2) * sin(dLat/2) + cos(lat1) * cos(lat2) * sin(dLon/2) * sin(dLon/2); 
        float c = 2 * atan2(sqrt(a), sqrt(1-a)); 
        float d = R * c;
    
        NSLog(@"Miles-->%f",d);
    
        return d;
    }
    
    @end
    

    I have not tested this on device but logically it should work.

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

Sidebar

Related Questions

I'm having a problem calling an outside application from a compiled ocaml application, pdflatex.
I am having trouble with the Hello Map Views tutorial from the Android Developer
I want to integrate a map of a Mall/Building having 7 floors in a
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
I'm trying to map a ManyToMany relationships between 2 tables, both having composite primary
I have an application that draws 3-d map view marked up lines that show
I'm working on an application with a map and there is a div in
I'm having a bit of a problem with my Android application. I have 2
I'm having some problems integrating MS MapPoint 2009 into my WinForms .Net 2.0 application
I'm having a little issue...I setup a rails application that is to serve a

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.