George Young George Young - 5 months ago 24
iOS Question

Objective c gps coordinates not working

I have followed many tutorials but none have worked. The coordinate always outputs 0.000000, 0.000000.

Here is my code for the location:

- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
currentLocation = (CLLocation *)[locations lastObject];

-(void)getLocation {
longitude = floorf(currentLocation.coordinate.longitude * 10000)/10000;


I have this in a button:

locationManager stopUpdatingLocation];
[self getLocation];

And I have this in the viewDidLoad:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];

I am using a fake location in the ios simulator in xcode so it should not output 0.000000.

Max Max

You need to request authorization to use location services.

if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    [self.locationManager requestAlwaysAuthorization];