0

I am using Xcode 6.I have some problems when I try to get User current Location using CLLocationManager. Even I added the NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription to Info.plist file. And also used [CLLocationManager requestWhenInUseAuthorization]. Then also I am getting console output as

2014-10-15 11:45:15.004 MapIOS8[1916:57908] Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gireesh K
  • 102
  • 7
  • so all you want is, fetch the current location of the user? – Rumin Oct 15 '14 at 06:42
  • 1
    You are clearly calling requestWhenInUse to late... Show your code. – Woodstock Oct 15 '14 at 06:45
  • What I want is ,I want to show the user current Location on map – Gireesh K Oct 15 '14 at 06:46
  • - (void)viewDidLoad { [super viewDidLoad]; CLLocationManager *myManager=[[CLLocationManager alloc]init]; myManager.delegate=self; if([CLLocationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { NSLog(@"Inside This method"); [myManager requestWhenInUseAuthorization]; } MKCoordinateRegion myregion; myregion.span.latitudeDelta=0.11; myregion.span.longitudeDelta=0.11; [myMap setRegion:myregion animated:YES]; } – Gireesh K Oct 15 '14 at 06:50
  • 1
    You shouldn't enable the "show current location" property until you have had a successful authorization callback to your CLLocationManagerDelegate delegate – Paulw11 Oct 15 '14 at 06:50
  • try this http://stackoverflow.com/questions/25911330/ios-8-mapview-current-location-not-fire – Rameshwar Gupta Oct 15 '14 at 07:12

2 Answers2

0

Have you tried writting the code in this order?

CLLocationManager *YourLocationManager = [[CLLocationManager alloc] init];
YourLocationManager.delegate = self;
[YourLocationManager requestWhenInUseAuthorization];
[YourLocationManager startUpdatingLocation];

yourMapView.delegate = self;
yourMapView.showsUserLocation = YES;

Also, to get the user location coordinate, you may have to implement this mapkit delegate method

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"%f, %f", userLocation.coordinate.latitude, userLocation.coordinate.longitude);

    [mapView selectAnnotation:userLocation animated:YES];
}
Asif Asif
  • 1,511
  • 14
  • 24
0

If you are using iOS Simulator try to reset location settings from Settings-> General-> Privacy-> Reset location & privacy. Then call:

[LocationManager requestAlwaysAuthorization];

At the first execution must appear a popup to allow the use of the current user's position. After allow the use of current location start your LocationManager with:

[LocationManager startUpdatingLocation];
Andr3a88
  • 679
  • 5
  • 13