views:

312

answers:

1

i am using these methods to get my location.all works fine in simulator.but on real device it runs very fast.how do i slow this down,also how do i show error only once if the device have not sim inserted and also for user denied to use current location. here are the methods--

-(void)GetCurrentLocation {
 // Create the location manager if this object does not
 // already have one.
 if (nil == locationManager)
  locationManager = [[CLLocationManager alloc] init]; 
 if (locationManager.locationServicesEnabled == NO) {
    UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [servicesDisabledAlert show];
    [servicesDisabledAlert release];
 [locationManager release];
    }       
else{
  locationManager.delegate = self;
  locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 
  [btnGPSFix setHidden:NO];
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:1.0];// Sub. duration  
  [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:btnGPSFix cache:YES];
  [self showMsg:@"Getting a GPS fix..." WithDelay:7];
  [UIView commitAnimations];
  [locationManager startUpdatingLocation];
 }
}

// Delegate method from the CLLocationManagerDelegate protocol.

  - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
 // If it's a relatively recent event, turn off updates to save power
 NSDate* eventDate = newLocation.timestamp;
  NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
 if (abs(howRecent) < 5.0) {
  [manager stopUpdatingLocation];  
  printf("latitude %+.6f, longitude %+.6f\n",newLocation.coordinate.latitude,newLocation.coordinate.longitude);
  LatitudeData = [[NSString alloc] initWithFormat:@"%f",newLocation.coordinate.latitude];
  LongitudeData = [[NSString alloc] initWithFormat:@"%f",newLocation.coordinate.longitude];
 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:1.0];// Sub. duration  
 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:btnGPSFix cache:YES];
  [self showMsg:@"GPS Acquired" WithDelay:4];
  [UIView commitAnimations];
  [self insertIntoDataBase];
  }
  // else skip the event and process the next one.
 }

here is my [self showMsg: WithDelay:] Method

 - (void)showMsg:(NSString*)Message WithDelay:(int)delay
 {
 CGRect frame = CGRectMake(30, 366, 259, 37);
 [btnGPSFix setTitle:Message forState:UIControlStateNormal];
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:1.0]; 
 frame.origin.y = 366;
 btnGPSFix.frame = frame; 
 [UIView commitAnimations]; 
 // Hide the view after the requested delay
 [self performSelector:@selector(HideGpsFixButton) withObject:nil afterDelay:delay]; 
}

Here is the HideGpsFixButton Method

- (void)HideGpsFixButton
{
 // Slide the view down off screen
 CGRect frame = CGRectMake(30, 366, 259, 37); 
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:1.0];
 frame.origin.y = 480;
 btnGPSFix.frame = frame; 
 [UIView commitAnimations];

}

i have checked in device it shows getting a gps fix message.device doesn't have sim inserted.i want to show only one message that your device doesn't have sim inserted or if user disallow location service then show the message location service is disabled by the user.any help appreciated.

+1  A: 

You can't, Apple does not expose any information information the sim, the cell radio, the network you are on, etc. If you want this functionality you should file a bug with Apple explaining why you need it.

Louis Gerbarg