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 12-16-2008, 09:26 PM   #24 (permalink)
varchar
Registered Member
 
Join Date: Aug 2008
Posts: 100
varchar is on a distinguished road
Default

Zword,

Can you post the code you are having trouble with and we can try to assist in debugging it?

In the meantime, here is code which works well:


Header

Code:

@interface MyTestGPSViewController : UIViewController <CLLocationManagerDelegate> {
	
	NSString *myCurrentLatitude;
	NSString *myCurrentLongitude;

	CLLocationManager *locationManager;
	CLLocation *currentLocation;


}

@property(nonatomic,retain) NSString *myCurrentLatitude;
@property(nonatomic,retain) NSString *myCurrentLongitude;

@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocation *currentLocation;

- (void)locationManager:(CLLocationManager *)manager
	didUpdateToLocation:(CLLocation *)newLocation
		   fromLocation:(CLLocation *)oldLocation;


@end

Implementation
(contains only excerpt of related code for GPS)
Code:



- (id) init {
	self = [super init];
	if (self != nil) {
	self.locationManager = [[[CLLocationManager alloc] init] autorelease];
		
	locationManager.delegate = self;
	
	locationManager.desiredAccuracy = kCLLocationAccuracyBest;
		
	[locationManager startUpdatingLocation];

	}
	


// Called when the location is updated
- (void)locationManager:(CLLocationManager *)manager
	didUpdateToLocation:(CLLocation *)newLocation
		   fromLocation:(CLLocation *)oldLocation
{	
	NSDate* newLocationeventDate = newLocation.timestamp;
	NSTimeInterval howRecentNewLocation = [newLocationeventDate timeIntervalSinceNow];

//	NSDate* oldLocationeventDate = newLocation.timestamp;
	//NSTimeInterval howRecentOldLocation = [oldLocationeventDate timeIntervalSinceNow];

	// Needed to filter cached and too old locations
	if ((!currentLocation || currentLocation.horizontalAccuracy > newLocation.horizontalAccuracy) &&
		(howRecentNewLocation < -0.0 && howRecentNewLocation > -10.0)) {
		if (currentLocation)
			[currentLocation release];
		
		currentLocation = [newLocation retain];
	}
	
}


	
	return self;
}
varchar is offline   Reply With Quote
 

» Advertisements
» Online Users: 402
14 members and 388 guests
Absentia, alisafl22, DaveDee, dbramhall, demas, erdinc27, fredidf, Hercule, heshiming, Johnsyfared, milanalina, roof44, Tusarari, waghman
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,603
Threads: 94,084
Posts: 402,783
Top Poster: BrianSlick (7,990)
Welcome to our newest member, alisafl22
Powered by vBadvanced CMPS v3.1.0

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