LocationManager not working second time I press my button

Discussion in 'iOS Programming' started by cklongshot, May 16, 2010.

  1. cklongshot macrumors newbie

    May 15, 2010
    I have a button when pressed gets the users location and returns the information pushing a second view controller onto the stack. However, when i go back using the navigation controller to my first view and press the button a second time it does not seem to push the view again.

    - (IBAction)CurrentLocation:(id)sender {
         [activityIndicator startAnimating];
         // Location Manager
         self.locationManager = [[CLLocationManager alloc] init];
         locationManager.delegate = self;
         locationManager.desiredAccuracy = kCLLocationAccuracyBest;
         [locationManager startUpdatingLocation];
            [super viewDidLoad];
    -(void)locationManager:(CLLocationManager *)manager
       didUpdateToLocation:(CLLocation *)newLocation
                fromLocation:(CLLocation *)oldLocation {
         if (startingPoint == nil) {
              self.startingPoint = newLocation;
              NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
              NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
              // Stack next View
              StoreListingsViewController *storeListings = [[StoreListingsViewController alloc] initWithNibName:@"StoreListings" bundle:nil];
              // pass url string to next view
              storeListings.latitudeString = latitudeString;
              storeListings.longitudeString = longitudeString;
              [latitudeString release];
              [longitudeString release];
              [self.navigationController pushViewController:storeListings animated:YES];
              [storeListings release];
              // Stop checking for updates to location
              [locationManager stopUpdatingLocation];
              // Stop activity Indicator
              [activityIndicator stopAnimating];
  2. cklongshot thread starter macrumors newbie

    May 15, 2010
    I solved this by removing my if statement for startingPoint. I was originally only accepting it to run if it was nil.

Share This Page