Reputation: 39384
I am new to iphone development.I am creating a map application.I have used following code in header file
@interface BrusMapSubviewcontroller : UIViewController<UIApplicationDelegate,CLLocationManagerDelegate> {
IBOutlet MKMapView *mapView;
IBOutlet UIToolbar *toolbar;
IBOutlet UIButton *location;
IBOutlet UIButton *backtocampus;
CLLocationManager *locationManager;
}
@property(retain,nonatomic) IBOutlet UIToolbar *toolbar;
@property(retain,nonatomic) IBOutlet UIButton *location;
@property(retain,nonatomic)IBOutlet UIButton *backtocampus;
@property (nonatomic, retain) CLLocationManager *locationManager;
-(IBAction) gosearch : (id) sender;
-(IBAction) backtocampus: (id)sender;
In the implementation class
-(IBAction) gosearch : (id) sender{
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
[locationManager startUpdatingLocation];
NSLog(@"inside go search");
}
-(IBAction) backtocampus: (id)sender{
MKCoordinateRegion region;
region.center.latitude=41.825672;
region.center.longitude=-71.402695;
region.span.latitudeDelta=0.001551;
region.span.longitudeDelta=0.005493;
mapView.mapType=MKMapTypeHybrid;
mapView.region=region;
NSLog(@"inside back to campus");
}
- (void)locationManager: (CLLocationManager *)manager
didUpdateToLocation: (CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[manager stopUpdatingLocation];
NSLog(@"inside update");
printf("\n Latitude = %s\n Longitude = %s",[NSString stringWithFormat:@"%.7f",newLocation.coordinate.latitude],[NSString stringWithFormat:@"%.7f",newLocation.coordinate.longitude]);
}
- (void)locationManager: (CLLocationManager *)manager
didFailWithError: (NSError *)error
{
printf("\nerror");
}
When i run in simulator "inside update" is printed in console and long and lat values.But if i run in ipod "inside go search" is alone printed in console.Why there is difference output in simulator and device.Thanks.
Upvotes: 0
Views: 465
Reputation: 77271
The simulator is preset to a location in California (~37.3, -122.0) , so when you start location manager on the simulator you get a call to didUpdateToLocation:fromLocation: right away with the preset location. That's the only location you'll ever get from the simulator.
On an iPhone it could take anywhere from a couple seconds to several minutes before it has a valid GPS location so it may take some time before you see the "inside update" message or the "error" message. But you should get one or the other eventually.
You can also change the distanceFilter and desiredAccuracy to control how often you get location updates.
Upvotes: 1
Reputation: 159
If I understand what you are asking, the reason for the difference from simulator to device is; the simulator is preset to Apple in CA location. So when you run the app on the device you will get your current location and when you run the app on the simulator you will get Apple in CA location.
Upvotes: 1
Reputation: 7136
The iPod doesn't embedded the GPS. So I suppose that it may cause this dysfunction.
Upvotes: 0