-(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";
- (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)]];
}
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)]]; }
- (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]
];
}