views:

94

answers:

1

hi , i want my app to get the exact location (longitude and latitude) of where he is as every second, it is possible ? i have this code so far, every 3 second the app get the current location but it doesnt update if i move...

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    NSLog(@"lol");


    [locationManager stopUpdatingLocation];



        if (wtf == 2) {
            [[NSUserDefaults standardUserDefaults] setObject:newLocation forKey:@"old"];
            NSLog(@"wtf");
            wtf =0;


        }

    oldLocation = [[NSUserDefaults standardUserDefaults] objectForKey:@"old"];

        double rep = [oldLocation distanceFromLocation:newLocation];
        NSString *label1 = [NSString stringWithFormat:@"%2.90f",oldLocation.coordinate.latitude];
        NSString *label2 = [NSString stringWithFormat:@"%2.90f",newLocation.coordinate.latitude];

    if ([label1 isEqual:label2]) {
        NSLog(@"penis");
    }

    labelm.text = label1;
    labelkm.text = label2;


}



- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {

}

-(void)actualise{





    [locationManager startUpdatingLocation];

}


- (void)viewDidLoad {
    [super viewDidLoad];
    wtf = 2;

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(actualise) userInfo:nil repeats:YES];
}
/*
+1  A: 

Use this code to initialize and start the location manager:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];

And implement didUpdateToLocation like this:

- (void) locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*) oldLocation 
{
   // This will be called every time the device has any new location information. 
}

There is no need to use any timers.

Martin Ingvar Kofoed Jensen
ok but i need to know the exact location every second so if i am running on the street every second it will change the location?
the1nz4ne
Setting distanceFilter and desiredAccuracy to the lowest will give you the most updates. But there is no why of saying that you will get an update for every second. You will only get updates when the GPS unit detects that it has moved.
Martin Ingvar Kofoed Jensen