0
votes

I am using simulator and changing the location to simulate the movement of device.

The problem that I have figured out is that:

In the following code, when I try to print the latitude and longitude values, the value are rounded off to 6 decimal digits(43.825885,-75.839785) while the original values that I enter in the simulator(Debug->Location) is 43.82588498,-75.83978498. (For these initial values, the didUpdateLocations delegate gets called)

Now the next location(Just next to the previous location) that I enter is 43.82499145,-75.84050195 which I must get 43.824991,-75.840502. But this time the didUpdateLocations delegate doesn't get called.

But when I now give 43.82110323,-75.85291386 (rounded to 43.821103,-75.852914), this time the didUpdateLocation delegate is called.

  • (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {

     CLLocationCoordinate2D coordinate = [[locations lastObject] coordinate];
     NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
     NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
    
     NSLog(@"here Latitude : %@", latitude);
     NSLog(@"here Longitude : %@",longitude);
    

    }

The following are my locationManager properties:

    _locationManager = [[CLLocationManager alloc] init];
    [_locationManager setDelegate:self];
    [_locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
    [_locationManager setDistanceFilter:300];
    [_locationManager startUpdatingLocation];
    [_locationManager startUpdatingHeading];

This is my mapView object's setup:

    self.mainMapView.delegate=self;
    [self.mainMapView setShowsUserLocation:YES];

Is this behavior because the OS is rounding off the Lat/Lon values? Or is it because I am using the simulator(which I don't think should be the problem because when I read similar questions, people have mentioned that if you simulate location then there shouldn't be any problem)?

I don't have an iOS device. Is it still possible that didUpdateLocation may work correctly on an actual device?

I am not able to figure out the bug here. I want the didUpdateLocations delegate to be called every time a slightest location update is made. Kindly guide me.

2

2 Answers

2
votes

Try removing your setDistanceFilter and letting locationManger use the default (kCLDistanceFilterNone). The distance filter tells your location manager to call didUpdateLocations only when the device has moved that amount or beyond. So, in your case, it will update the location every 300 meters.

1
votes

The first thing you need to do is to add one or both of the following keys to your Info.plist file: NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription

Next you need to request authorization for the corresponding location method, WhenInUse or Background. Use one of these calls: [self.locationManager requestWhenInUseAuthorization] [self.locationManager requestAlwaysAuthorization]

// Check for iOS 8 if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; }