-4

Can't get current location from my code:

(IBAction)getdetails:(id)sender {
    manager.delegate = self;
    manager.desiredAccuracy = kCLLocationAccuracyBest;
    [manager startUpdatingLocation];
}

#pragma mark - CLLocationManagerDelegate
(void)locationmanager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        _latitudelabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        _latitudelabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
    }
Hugo Yates
  • 2,081
  • 2
  • 26
  • 24
  • Please solve this problm..I also add tw frame work core location,mapkit.. – harsh rajput May 19 '15 at 11:57
  • Please format your question properly. Use `- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations`. [Reference](http://stackoverflow.com/questions/12602463/didupdatelocations-instead-of-didupdatetolocation) – Bista May 19 '15 at 12:01
  • Please update your question with the problem you are facing, and also see it is properly formatted, so that people who wish to help can do so. – Vivek Molkar May 19 '15 at 12:12

1 Answers1

1

In iOS 8 you need to do two extra things to get location working:

  1. Add a following key to your Info.plist: NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription

  2. Request authorization from the location manager asking it to start.

    [locationManager requestWhenInUseAuthorization];    // or 
    [locationManager requestAlwaysAuthorization];
    

You can get more info from Apple Docs.

For Important info on CoreLocation you should also have a look at this Blog

Vivek Molkar
  • 3,910
  • 1
  • 34
  • 46