views:

58

answers:

3

Hi, I am trying to create simple GPS application just to display simple data in simulator. I have no errors just cant obtain data. "didFailWithError" method is the only I can get to work :), this is the code:

- (void)viewDidLoad 
{  
 [super viewDidLoad];

 lm = [[CLLocationManager alloc] init];
 if([CLLocationManager locationServicesEnabled])
 {
  lm.delegate = self;
  lm.desiredAccuracy = kCLLocationAccuracyBest;
  //lm.distanceFilter = 1000.0f;
  [lm startUpdatingLocation];
 }

}


- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation{
 NSString *lat = [[ NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
 txtLatitude.text = lat;

 NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
 txtLongitude.text = lng;

 NSString *acc = [[NSString alloc] initWithFormat:@"%g", newLocation.horizontalAccuracy];
 txtAccuracy.text = acc;

 [acc release];
 [lat release];
 [lng release];
}
- (void) locationManager:(CLLocationManager *)manager 
didFailWithError: (NSError *) error
{
 NSString *msg = [[NSString alloc] initWithString:@"Error obtaining location"];
 UIAlertView *alert = [[ UIAlertView alloc] initWithTitle:@"Error" 
              message:msg 
             delegate:nil 
             cancelButtonTitle:@"Done" 
             otherButtonTitles:nil];
 [alert show];
 [msg release];
 [alert release];
}
+1  A: 

It doesnt move ever in the simulator.

http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/125-Using_iPhone_Simulator/iphone_simulator_application.html

"Core Location Functionality

The relocation reported by the CoreLocation framework in the simulator is fixed at the following coordinates (accuracy 100 meters), which correspond to 1 Infinite Loop, Cupertino, CA 95014.

Latitude: 37.3317 North Longitude: 122.0307 West"

You could try adding a simple random or timed event which pings the didUpdate... method explicitly with fake data of your preference.

Warren Burton
I write this code. Run this code with breakpoint in didUploadToLocation method. But code never reach in there. Always finish in fail method. Why is this happening?
Whats the fail reason
Warren Burton
No reason just didUpload method is not invoked.
A: 
  1. The simulator is displaying my real GSP location.
  2. The simulator is always displaying 37Nx122W, Apple HQ.
  3. The simulator is displaying nothing, didUpdate NEVER gets called at all.

The user is having problem #3. Everyone is answering as if #1 or #2 are happening.

Many people (including me) always have #3 problems. I've never seen anyone answer #3. They always just say "oh, #2".

Sally
A: 

You could try adding a simple random or timed event which pings the didUpdate... method explicitly with fake data of your preference.

But HOW would we "randomly ping didUpdate with fake data using a timer"????

Tell "how"... not "just do this".

How?

Sally
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(pingLocMan:) userInfo:nil repeats:YES];
Warren Burton
-(void)pingLocMan:(NSTimer *)aTimer{ [self locationManager:lmdidUpdateToLocation:aFakedCLLocationfromLocation:anotherFakedCLLocation];}
Warren Burton