Question

I am wondering if there is away to send the lat and long of a person's location to a URL? It would also need to have their UDID number to match with the database.

Here is what I have so far:

-(void)viewDidLoad {    
     NSString *query = [[NSString alloc] initWithFormat:
                          @"http://example.com/ihome.php?uid=%@", 
                          [[UIDevice currentDevice] uniqueIdentifier], 
                          @"&year=2010%@"];
     NSURL *url = [[NSURL alloc] initWithString:query];
     NSURLRequest *requestObj = [ NSURLRequest requestWithURL: url ];
     webView.opaque = NO;
     webView.backgroundColor = [UIColor clearColor];
     [webView loadRequest: requestObj ];
}
Was it helpful?

Solution

You have to calculate the longitude and the latitude before to request the URL.

- (void) viewDidLoad {
    self.locationManager = [[[CLLocationManager alloc] init] autorelease];
    self.locationManager.delegate = self; // send location updates to this object
    [self.locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
     NSLog(@"Your location: %@", [newLocation description]);

     NSString *query = [[NSString alloc] initWithFormat:
                          @"http://mysite.com/ihome.php?uid=%@&longitude=%d&latitude=%d", 
                          [[UIDevice currentDevice] uniqueIdentifier], 
                          @"&year=2010%@",
                          newLocation.longitude,
                          newLocation.latitude];
     NSURL *url = [[NSURL alloc] initWithString:query];
     NSURLRequest *requestObj = [ NSURLRequest requestWithURL: url ];
     webView.opaque = NO;
     webView.backgroundColor = [UIColor clearColor];
     [webView loadRequest: requestObj ];

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"Error: %@", [error description]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top