0

I'm trying to get the device's latitude/longitude, and I've followed this tutorial exactly. http://ios-blog.co.uk/tutorials/getting-the-users-location-using-corelocation/

When I run the program the labels should update to the latitude and longitude (I set the simulator's location to "Apple" but the labels don't update at all. I also never get the prompt asking me to allow the app to use the device's location. I tried deleting the app from the simulator and running it again fresh, but that didn't change anything.

Anyone have any idea why this isn't working? I wonder if it's something to do with the latest version of Xcode (I'm using 6) not working with the tutorial that worked for a previous version. Thoughts?

Cœur
  • 37,241
  • 25
  • 195
  • 267
alu
  • 190
  • 1
  • 9

2 Answers2

1

You need to add a NSLocationWhenInUseUsageDescription key to your info.plist.

You also need to call:

locationManager = [[CLLocationManager alloc] init];
[locationManager requestWhenInUseAuthorization];
Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51
0

If you are building for iOS 8, did you ask for authorization before starting CLLocationManager, as described here?: Xcode 6/iOS 8 Location Simulation doesn't work

Essentially, calling one of these methods:

[self.locationManager requestWhenInUseAuthorization];  // For foreground access
[self.locationManager requestAlwaysAuthorization]; // For background access
Community
  • 1
  • 1
Peter Heide
  • 519
  • 4
  • 13
  • That did it, in addition to adding to the info.plist. Thanks a bunch! I searched SO for this, but didn't specify ios8, so that's probably why I didn't find the answer. Now I know for next time! – alu Oct 29 '14 at 17:44