Wrong Distance CLLocation

223 Views Asked by At

In this code I receive a wrong distance, _latitude and _longtitude are NSString. Any suggestion to correct this?

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [locationManager startUpdatingLocation];
        CLLocation *location = [locationManager location];

        CLLocationCoordinate2D coord;
        coord.latitude = [_latitude doubleValue];
        coord.longitude = [_longitude doubleValue];

        CLLocation *anotLocation = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude];
        _distancia = [NSNumber numberWithFloat:([location distanceFromLocation:anotLocation]/1000)];
1

There are 1 best solutions below

0
On

check out this singleton implementation of location controller

https://github.com/hackerinheels/locationcontroller

with this just call

    CLLocation *currLocation = [[LocationController sharedLocationInterface]getCurrentLocation];