I am trying to send some parameters to my phpMyAdmin tables that contains a filed called latitude and longitude. Since then, i need to obtain the device coordinates and transform them into a string.
I have followed the Ray Wenderlich tutorial but i am still getting "nil" in my parameters. Take a look at the following code:
1 - I have added the framework to the code and imported the CoreLocation files to my "ResumeView.h", also, declared both latitude and longitude Strings.
#import <CoreLocation/CoreLocation.h>
@interface ResumeView : GAITrackedViewController <UIAlertViewDelegate, CLLocationManagerDelegate>
{
NSString *latitude;
NSString *longitude;
2 - Now, on my "ResumeView.m" i've add the rest of the code as followed by the tutorial...
@implementation ResumeView {
CLLocationManager *manager;
}
@synthesize latitude;
@synthesize longitude;
3 - Now, on viewDidLoad...
- (void)viewDidLoad
{
[super viewDidLoad];
manager = [[CLLocationManager alloc] init];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager startUpdatingLocation];
4 - Then, these functions were introduced along my code, of course, before the POST parameters could be sent.
#pragma mark CLLocationManagerDellegate Methods
-(void) locationManager:(CLLocationManager *) manager didFailWithError: (NSError *)error {
NSLog(@"error: %@", error);
NSLog(@"Failed to get location! :(");
}
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"Location: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
latitude = [NSString stringWithFormat: @"%.8f", currentLocation.coordinate.latitude];
longitude = [NSString stringWithFormat: @"%.8f", currentLocation.coordinate.longitude];
}
}
5 - And here is where the problem makes comes, both coordinate values are "nil"and cannot be sent to the database.
@"latitude":latitude, // <---- error here! is nil when sending to database!
@"longitude":longitude, // <---- error here! is nil when sending to database!