Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-09-2009, 01:46 PM   #2 (permalink)
Dutch
Humbled Student
 
Dutch's Avatar
 
Join Date: Apr 2009
Location: Long Island, NY
Age: 32
Posts: 883
Dutch will become famous soon enough
Send a message via AIM to Dutch
Default

Quote:
Originally Posted by expertadvisor View Post
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
	}

}
Dutch is offline   Reply With Quote
 

» Advertisements
» Online Users: 718
21 members and 697 guests
Absentia, ADY, Ammad, ayesha25, Bertrand21, BrianSlick, coreyb, dacapo, Gaz, GHuebner, givensur, jeewan, kapps11, kosicki123, msovani, mutantskin, nobre84, pipposanta, rivers123, trunglee, wynonarr69
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,181
Threads: 93,920
Posts: 402,154
Top Poster: BrianSlick (7,968)
Welcome to our newest member, ayesha25
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.