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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:21:06+00:00 2026-06-11T20:21:06+00:00

This may be simple for those who interested in GPS based applications.In my app,i

  • 0

This may be simple for those who interested in GPS based applications.In my app,i am trying to track the location of a user and have to draw the user’s path on map.So on each updated point i have to populate an array which is having the values like latitude,longitude,altitude,current speed,distance travelled of that particular location.But when i am trying it on device,my app crashes while taking these values.I think this method is calling more than 10 times per second.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation
{
}

And taking all these bulk values at a very fast rate causes the issue.I tried to implement a condition in this method so that the array should update at a time interval of 5 seconds.this is what i tried.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation  fromLocation:(CLLocation *)oldLocation{

      CLLocation*  updatedLocation = [newLocation retain];
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
        NSDate *myDate = (NSDate *)[prefs objectForKey:@"myDateKey"];

        NSDate *lastDate = (NSDate *)newLocation.timestamp;
        NSTimeInterval theDiff = [lastDate timeIntervalSinceDate:myDate];

       if (theDiff > 5.0f || myDate == nil){
            //do your webservices stuff here



          if (newLocation.horizontalAccuracy < 0)
        {
            // No Signal
            if([self conformsToProtocol:@protocol(CoreLocationControllerDelegate)])
            {

                [self gpsSignalStatus:@"No Signal"];
            }

        }
        else if (newLocation.horizontalAccuracy > 65)
        {
            // Poor Signal
            if([self conformsToProtocol:@protocol(CoreLocationControllerDelegate)])
            {

                [self gpsSignalStatus:@"Poor Signal"];
            }
        }
        else if (newLocation.horizontalAccuracy <= 65.0)
        {
            // Fair
            if([self conformsToProtocol:@protocol(CoreLocationControllerDelegate)])
            {

                [self gpsSignalStatus:@"Fair"];
            }

        }
        else if (newLocation.horizontalAccuracy <= 20.0)
        {
            // Good
            if([self conformsToProtocol:@protocol(CoreLocationControllerDelegate)])
            {

                [self gpsSignalStatus:@" Good"];
            }

        }

        int degrees = newLocation.coordinate.latitude;
        double decimal = fabs(newLocation.coordinate.latitude - degrees);
        int minutes = decimal * 60;
        double seconds = decimal * 3600 - minutes * 60;
        NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                         degrees, minutes, seconds];
        latitudeLabel.text = lat;
        degrees = newLocation.coordinate.longitude;
        decimal = fabs(newLocation.coordinate.longitude - degrees);
        minutes = decimal * 60;
        seconds = decimal * 3600 - minutes * 60;
        NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                           degrees, minutes, seconds];
        longitudeLabel.text = longt;
        speedLabel.text = [NSString stringWithFormat:@"SPEED: %f", [newLocation speed]];
        altitudeLabel.text = [NSString stringWithFormat:@"ALTITUDE: %f", [newLocation altitude]];
        [mapView removeAnnotations:[mapView annotations]];
        MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
        pa.coordinate = newLocation.coordinate;
        pa.title = @"Current Location";
        [mapView addAnnotation:pa];
        [pa release];
        NSString *latlongString = [NSString stringWithFormat:@"%f,%f", newLocation.coordinate.latitude,newLocation.coordinate.longitude];
        [latLongArray addObject:latlongString];
        NSLog(@"%@",latLongArray);
        NSLog(@"Speed :: %g meters/sec",newLocation.speed);


        [points addObject:newLocation];
        NSInteger tot = [points count];
        MKMapPoint* pointsToUse=malloc(sizeof(CLLocationCoordinate2D) * tot);
        if(tot>1)
        {
            //i=tot-1;i<tot;i++
            for(int i=0;i<tot;i++)
            {

                CLLocation *Loc=[points objectAtIndex:i];
                CLLocationDegrees latitude = Loc.coordinate.latitude;
                //   [TravellingCoordinates addObject:location];
                CLLocationDegrees longitude = Loc.coordinate.longitude;
                CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
                MKMapPoint point = MKMapPointForCoordinate(coordinate);
                pointsToUse[i] = point;




                NSString *latitudestr = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
                NSLog(@"Latitude: %@", latitudestr);


                NSString *longitudestr = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
                NSLog(@"Longitude: %@", longitudestr);

                NSString *altitudestr = [[NSString alloc] initWithFormat:@"%g",newLocation.altitude];
                NSLog(@"altitude: %@", altitudestr);

                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                [formatter setDateFormat: @"HH:mm:ss"];
                NSString *LocationTime=[formatter stringFromDate:newLocation.timestamp];
                NSLog(@"LocationTime:%@",LocationTime);
                NSTimeInterval timeSinceLastLocation = [oldLocation.timestamp timeIntervalSinceDate:newLocation.timestamp];
                CGFloat speed = newLocation.speed;
                NSString *speedstr=[[NSString alloc]initWithFormat:@"%f",speed];
                NSLog(@"%@",speedstr);

                CLLocationDistance distance=0;;
                distance=distance+[newLocation distanceFromLocation:oldLocation];
                NSString *distancestr=[[NSString alloc]initWithFormat:@"%f",distance];

               // NSString *distancestr=[[NSString alloc]initWithFormat:@"%f",distance];

                [firstJsonDictionary setObject:latitudestr forKey:@"latitude"];
                [firstJsonDictionary setObject:longitudestr forKey:@"longitude"];
                [firstJsonDictionary setObject:altitudestr forKey:@"altitude"];
                [firstJsonDictionary setObject:LocationTime forKey:@"timestamp"];
                [firstJsonDictionary setObject:speedstr forKey:@"speed"];
                [firstJsonDictionary setObject:distancestr forKey:@"distance"];

                for(int i=0;i<10;i++){

                    [arr addObject:firstJsonDictionary];
                    // [firstJsonDictionary release];
                }
                NSError *error=nil;
                NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&error];
                NSString *jsonString = [[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
              //  NSLog(@"jsonData as string:\n%@", jsonString);
                NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
                [defaults setObject:jsonString forKey:@"jsonarraydata"];



                } 

            }

        // create the polyline based on the array of points.
        _routeLine = [MKPolyline polylineWithPoints:pointsToUse count:tot];
        [mapView addOverlay:_routeLine];
        free(pointsToUse);
           NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
           [prefs setObject:lastDate forKey:@"myDateKey"];
           [prefs synchronize];

           [self distanceTravelled:newLocation];
       [self loadRoute];


       }



    }

Any idea will be appreciable. Thanks in advance.

  • 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-11T20:21:08+00:00Added an answer on June 11, 2026 at 8:21 pm

    When you allocating your locationManager you should set a distance filter:

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
    locationManager.distanceFilter = 100.0;
    

    If you don’t set the distance filter it takes the default value kCLDistanceFilterNone and you will be notified about ALL movements(i.e the method didUpdateLocation will be called very often)

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

Sidebar

Related Questions

this may be stupidly simple but I'm trying to figure out a way to
This may be a simple answer, but I'm trying to add a dom-created element
Okay this may be a simple question but I have yet to come with
This may be a simple question but I can;t find the answer anywhere. Here
This may be a simple fix and maybe I'm missing something obvious, but when
This may well be simple, but I'm new to Drupal. The organization I work
This may be a simple question though can´t figure out how to do it.
This may be very simple question,But please help me. i wanted to know what
This may be super simple - but I'm struggling to spot what's going on.
Okay, This may be really simple or it may not even be possible, or

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.