1

I have an button, when you press it, you get the location. It only works on initial launch, not subsequent uses. Code below

- (IBAction)getLocationCoordinates:(UIButton *)sender {
if ([CLLocationManager locationServicesEnabled]) {
    self.locationManager = [[CLLocationManager alloc]init];
    self.locationManager.delegate = self;
    [self.locationManager startUpdatingLocation];
}


}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{

CLLocation *location = [locations lastObject];
[self.locationManager stopUpdatingLocation];
NSLog(@"%f %f", location.coordinate.longitude, location.coordinate.latitude);
self.locationProperty = location;

}
noobsmcgoobs
  • 2,716
  • 5
  • 32
  • 52

1 Answers1

0

You will not get new location from didUpdateLocation if there is no significant changes of location (not moving).

I have a detailed complete solution for location update on both foreground and background for iOS 7, you may visit: Background Location Services not working in iOS 7 for more details.

The link will lead you to a complete solution on Github and also a detail blog post.

Community
  • 1
  • 1
Ricky
  • 10,485
  • 6
  • 36
  • 49
  • Cool. I will check it out. When I change the simulated location, I do not get the new location, I get the old one. Say I choose Mexico City, then I change to New York, I get data for Mexico City again. I might not be implementing CLLocationManager correctly also. – noobsmcgoobs May 21 '14 at 00:39
  • I believe the way your test the location is not correct. Your physical device has to move a short distance, because iOS use accelerometer to know if the device is actually moving or not. Or you know how to stimulate the movement of accelerometer like http://www.scottlogic.com/blog/2014/03/19/simulator-enhancements.html – Ricky May 21 '14 at 02:57
  • @Ricky: Please avoid signing off your posts with "Please upvote...". It just adds noise. – Matt Aug 06 '15 at 06:37