1

Hi i want to call the webservice whenever there is a location change of 50 meters(not less than this). I have tried using significant changes but it works for minimum 500 meters and startupdatelocations will call all the time. So How can i detect if the device moved 50 or 100 meters from the location.

I have used the distance filter as 50 meters as said in many stackoverflow questions. But it doesnt work before moving to 50 meters i got the location updates in device.

Here some one explained about distance filter - iphone core location: distance filter how does it work?

Community
  • 1
  • 1
Cintu
  • 913
  • 2
  • 16
  • 32
  • But it doesnt work. If you give distancefilter as 50 still i get the update in location before 50 m location change – Cintu Nov 26 '15 at 05:35

1 Answers1

5

It's Very Easy.

First Write in your ViewDidload Method To alloc CLLocationManager.

Here i set 50M distance .

locationManager = [[CLLocationManager alloc] init];

    //there will be a warning from this line of code
    [locationManager setDelegate:self];

    //and we want it to be as accurate as possible
    //regardless of how much time/power it takes
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

    //set the amount of metres travelled before location update is made
    [locationManager setDistanceFilter:50];
    [locationManager requestAlwaysAuthorization];
    [locationManager requestWhenInUseAuthorization];
    [locationManager startUpdatingLocation];

So Every 50 Meter change Device This Method is called :

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    if (locations.count > 0) {
        CLLocation *location = locations.lastObject;
        User_latitude = [NSString stringWithFormat:@"%f",location.coordinate.latitude];
        User_longitude = [NSString stringWithFormat:@"%f",location.coordinate.longitude];
        NSLog(@"latitude = %f",location.coordinate.latitude);
        NSLog(@"longitude = %f",location.coordinate.longitude);
        [self webservice_UpdateLocation];
    }
}
Maulik Patel
  • 397
  • 4
  • 15
  • 1
    I have tried this but in device if you move less than 50m also it will give the location update. distance filter is not for detecting the 50 meter location change – Cintu Nov 26 '15 at 05:32
  • @Anbu.Karthik - Do the above works? if i dont move also i m seeing some updates! – Cintu Nov 26 '15 at 05:51