Last active
December 10, 2015 19:38
-
-
Save patelrohan/4482451 to your computer and use it in GitHub Desktop.
Distance calculation using Locationamanger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)findCurrentLocation | |
{ | |
if(nil==self.locationManager) | |
{ | |
self.locationManager= [[[CLLocationManager alloc]init]autorelease]; | |
} | |
locationManager.delegate=self; | |
//locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters; | |
locationManager.desiredAccuracy=kCLLocationAccuracyBest; | |
//locationManager.distanceFilter = kCLDistanceFilterNone; | |
locationManager.distanceFilter = 2.0; | |
[locationManager startUpdatingLocation]; | |
} | |
- (void)locationManager:(CLLocationManager *)manager | |
didUpdateLocations:(NSArray *)locations | |
{ | |
currentLocation=[locations lastObject]; | |
NSDate* eventDate = currentLocation.timestamp; | |
NSLog(@"Current time stamp %@",eventDate); | |
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; | |
NSLog(@"How recent %d",abs(howRecent)); | |
if (abs(howRecent) < 15.0) | |
//if (howRecent < -0.0 && howRecent > -10.0) | |
{ | |
if([locationArray count]>1) | |
{ | |
previousLocation=[locationArray objectAtIndex:[locationArray count]-1]; | |
long double dist=[currentLocation distanceFromLocation:previousLocation]; | |
if(dist < 5.0) | |
{ | |
totalDistance= totalDistance + dist; | |
[viewControllerDelegate updateDistanceLabel]; | |
} | |
} | |
//NSLog(@"from singleton class lat---> %f - long---->%f", currentLocation.coordinate.latitude,currentLocation.coordinate.longitude); | |
} | |
[locationArray addObject:[locations lastObject]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment