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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-31-2009, 12:06 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 29
Default My gps position is always (null)

I've used this code to get my position and it is normally logged so I can see it works.

Code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
	
	if (startingPoint == nil)
		self.startingPoint = newLocation;
	
	NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.latitude];
	NSLog(@"%@", latitudeString);
	self.myLatitude = latitudeString;
	[latitudeString release];
	
	NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.longitude];
	NSLog(@"%@", longitudeString);
	self.myLongitude = longitudeString;
	[longitudeString release];
	
}
But I need to use my position with a webservice, so I logged the two variables on viewLoad, but they are always (null).
Can someone suggest me how can I access the two coordinates outside the didUpdateToLocation method?
Thanks in advance.
azimo is offline   Reply With Quote
Old 08-03-2009, 10:08 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 29
Default

I post some more code to see if someone can help me:

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	[[self locationManager] startUpdatingLocation];
	
	if (!(myLatitude)) {
		NSLog(@"no location found");
	}
	
	[self myCurrentLocation];
}

/**
 Return a location manager -- create one if necessary.
 */
- (CLLocationManager *)locationManager {
	
    if (locationManager != nil) {
		return locationManager;
	}
	
	locationManager = [[CLLocationManager alloc] init];
	locationManager.delegate = self;
	
	return locationManager;
}

/**
 Conditionally enable the Add button:
 If the location manager is generating updates, then enable the button;
 If the location manager is failing, then disable the button.
 */
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation {
	
	NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.latitude];
	NSLog(@"%@", latitudeString);
	self.myLatitude = latitudeString;
	[latitudeString release];
	
	NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.longitude];
	NSLog(@"%@", longitudeString);
	self.myLongitude = longitudeString;
	[longitudeString release];
	
}

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error {

}

- (void)myCurrentLocation {
	
	NSLog(@"%@", myLatitude);
	
}
In my console output I have
Code:
no location found
(null)
37.3317°
-122.031°
The output generated from the startUpdatingLocation is displayed after the one from myCorrentLocation (that in this way is null): how do I prevent this? How could I make my app to wait for the coordinates? Should I set a timer or is there a better way?
azimo is offline   Reply With Quote
Old 06-22-2010, 02:27 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 25
Default

The problem is that you are not actually receiving new coordinates. The coordinates that are being produced are the coordinates of Apple's HQ and are inputed by default. There is no problem with timing, it is not receiving new coordinates.

If you want to check it out, go to Google Maps and type in loc: 37.3317°
-122.031° and see what you find.
HockeyHippo is offline   Reply With Quote
Reply

Bookmarks

Tags
gps

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 261
15 members and 246 guests
@sandris, ADY, Alsahir, dacapo, Dani77, Desert Diva, djohnson, HemiMG, jansan, JasonR, MarkC, prchn4christ, smethorst, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0