Quote:
Originally Posted by expertadvisor
Guys-
Is the gps on by default? if we are creating an app that interacts with the gps, is the gps always on or how do we make sure its always ON automatically??
Many TIA 
|
define "ON"... In other words, when your app loads and you want to use the GPS, you need to request permission from the user using something like this
Code:
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];
[locmanager startUpdatingLocation];
Once you call startUpdatingLocation, the user will be asked whether or not to allow your app access to GPS data.
If they click NO you get an error
Code:
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"Error Encountered");
}
if they click YES, you must handle it in the following code:
Code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if (wasFound) return;
numberOfLocationUpdates++;
NSDate* newLocationEventTime = newLocation.timestamp;
NSTimeInterval howRecentNewLocation = [newLocationEventTime timeIntervalSinceNow];
// filter cached and previous locations
if ((!currentLocation || currentLocation.horizontalAccuracy >= newLocation.horizontalAccuracy) && (howRecentNewLocation < -0.0 && howRecentNewLocation > -10.0)) {
if (currentLocation) {
[currentLocation release];
}
currentLocation = [newLocation retain];
}
if (currentLocation || numberOfLocationUpdates >= 15) {
[locmanager stopUpdatingLocation];
numberOfLocationUpdates = 0;
//Use newLocation here
}
}