Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

icinnamon

macrumors newbie
Original poster
Sep 7, 2007
13
0
I'm using CoreLocation but the latitude and longitude is not returning a negative. For example, my latitude is -118, but corelocation is returning 118.
I am using newLocation.coordinate.latitude. How do I fix this?
Thanks!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Can you post the code you are using to get and display this? My first thought is that you are somehow loosing the sign, possibly by store or displaying as an unsigned type...
 

icinnamon

macrumors newbie
Original poster
Sep 7, 2007
13
0
Thanks!
Here's my code:
Code:
-(void)updateLatitude:(NSString *)latitude andLongitude:(NSString *) longitude {
	latitudeText.text = latitude;
	longitudeText.text = longitude;
	
	
	loadingText.text = @"Starting...";
	[[MyCLController sharedInstance].locationManager startUpdatingLocation];
	NSString *lat = [ latitude stringByAddingPercentEscapesUsingEncoding: 4 ];
	NSString *lon = [ longitude stringByAddingPercentEscapesUsingEncoding: 4 ];
	NSString *carrier = [ @"ATT" stringByAddingPercentEscapesUsingEncoding: 4 ];
	NSString *reception = [ @"7" stringByAddingPercentEscapesUsingEncoding: 4 ];
	loadingText.text = @"Sending...";
	NSString *myURL = [ NSString stringWithFormat: @"http://receptionmap.com/uploadForiPhone.php?lat=%@&lon=%@&carrier=%@&reception=%@", lat, lon, carrier, reception ];
	[ NSData dataWithContentsOfURL: [ NSURL URLWithString: myURL ] ];
	loadingText.text = @"Uploaded";

It is not displaying the negative on the screen or in the database (online)
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Call me stupid, but I don't see where you get the current location in that code.

Oh, and you shouldn't use 4 as your string encoding: use NSUTF8StringEncoding, just incase the number changes in future version of the SDK...
 

icinnamon

macrumors newbie
Original poster
Sep 7, 2007
13
0
Okay I'll do that instead of 4

And that code is actually the "callback" method (is that what it's called in Objective-C.... I'm used to Python dev :)).

This is the code that calls that method (this code is in MyCLController.m):
Code:
- (void)locationManager:(CLLocationManager *)manager
	didUpdateToLocation:(CLLocation *)newLocation
		   fromLocation:(CLLocation *)oldLocation
{
	[self.delegate updateLatitude: 
	 [NSString stringWithFormat:@"%lf", 
	  fabs(newLocation.coordinate.latitude)] 
	 andLongitude: 
	 [NSString stringWithFormat:@"%lf", 
	  fabs(newLocation.coordinate.longitude)]];
	
}
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Okay I'll do that instead of 4

And that code is actually the "callback" method (is that what it's called in Objective-C.... I'm used to Python dev :)).

This is the code that calls that method (this code is in MyCLController.m):
Code:
- (void)locationManager:(CLLocationManager *)manager
	didUpdateToLocation:(CLLocation *)newLocation
		   fromLocation:(CLLocation *)oldLocation
{
	[self.delegate updateLatitude: 
	 [NSString stringWithFormat:@"%lf", 
	  fabs(newLocation.coordinate.latitude)] 
	 andLongitude: 
	 [NSString stringWithFormat:@"%lf", 
	  fabs(newLocation.coordinate.longitude)]];
	
}

Um... you know what absolute value is, right? =) fabs is taking newLocation.coordinate.latitude and .longitude and forces them to positive, so you are asking to lose the negative with that code.

-Lee
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
it's always something, huh?

The only time I can think of with location stuff you'd want absolute value is dealing with distance travelled. You might do something like:
Code:
- (void)locationManager:(CLLocationManager *)manager
	didUpdateToLocation:(CLLocation *)newLocation
		   fromLocation:(CLLocation *)oldLocation
{
	double latitudeDelta = fabs(newLocation.coordinate.latitude - oldLocation.coordinate.latitude);
	double longitudeDelta = fabs(newLocation.coordinate.longitude - oldLocation.coordinate.longitude);
	double distance = sqrt(latitudeDelta*latitudeDelta + longitudeDelta*longitudeDelta);
	[self.delegate setDistanceTravelled: 
	 [NSString stringWithFormat:@"%lf", 
	  distance]  
	];
}

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.