开发者

iphone getting user location at time intervals

开发者 https://www.devze.com 2023-03-18 08:19 出处:网络
I browsed through some of the questions in stackoverflow but I couldn\'t get a clear picture. I am working on an iPhone application that involves getting the user\'s location through GPS and processin

I browsed through some of the questions in stackoverflow but I couldn't get a clear picture. I am working on an iPhone application that involves getting the user's location through GPS and processing based on the value that I got. I just wanted to make sure that how should I implement this? Using this method :

[locationManager startUpdatingLocation]

gives me the accurate location but it keeps on updating often that I do not want. I would like to get the user's location on a periodic basis.i.e., like every 2 minutes. How do I implement that?

The method I thought (10 second interval):

- (void)viewDidLoad { 
    self.locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.distanceFilter = kCLDistanceFilterNone;
    NSTimer *currentTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(theActionMethod) userInfo:nil repeats:YES];
}

and in the action method for the timer :

- (void)theActionMethod {
     [locationManager startUpdatingLocation];
}

and the method didUpdatetoLocation:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
     self.startingPoint = newLocation;
     NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g\u00B0", newLocation.coordinate.latitude];
     NSLog([@"Latitude : " stringByAppendingString:latitudeString]);
     [latitudeString release];
     [locationManager stopUpdatingLocation];
}

Now I am getting a value that remains the same throughout. Every 10s the location is updated but all values remain the same (I tried printing longitude, horizontal accuracy,altitude,vertical accuracy etc.). So please help me how to get the exact(atleast somewhat accurate because I know that GPS is not accurate)user's location for every 2 minutes.

And I would also like to know how to implement the monitoringRegions and significantlocationchange thing. Does anyone s开发者_开发知识库uccessfully implemented it? I couldn't do it. I did not notice any change (I printed something in didEnterRegion which was never printed even when I went back and forth in and out of the region ). Thanks a lot in advance.


Just do that same thing you're already doing. Just ignore the delegate method and change theActionMethod: to use the locationManager.location property however you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号