I am getting the current location using CLLocationManager and i am getting the latitude and longitude values of the current location. I haven't used the Mapview in my app. So whenever the current location is changed, that time i want to update the current location to the server. And every 5 minutes i need to call the web service and update the current location to the server in the both background mode and the foreground mode.
-(void) getCurrentLocation
{
// To get the current location of the place
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; //whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyBest; //100 m
//Start the location manager, then only updates the current location
[locationManager startUpdatingLocation];
}
/In Location manager delegate method, if the location is updated it will call and get the values from the newLocation using CLLocation
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *lat = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *lon = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"dLatitude : %@", lat);
NSLog(@"dLongitude : %@",lon);
self.reverseGeocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate] autorelease];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
//Stop the location manager
[locationManager stopUpdatingLocation];
}
Whenever the location is changed, that time i want to get the latitude and longitude for the particular location.
Thanks!