0

I am creating an app that allows the user to take a photo or select one from their photo reel, and email it to a specific address. The following code works, however, should a person take a photo, and then move before sending the email, the GPS location is inaccurate.

Is there a way I can:

  • Take a photo, store the Lat & Long of where the photo was taken to variables
  • Select a photo from the photo reel, extract the lat & long, and store to variables

Here is my code:

- (IBAction)takePhoto
{
    picker1 = [[UIImagePickerController alloc] init];
    picker1.delegate = self;
    [picker1 setSourceType: UIImagePickerControllerSourceTypeCamera];
    [self presentViewController:picker1 animated:YES completion:NULL];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];


}

- (IBAction)chooseExisting
{
    picker2 = [[UIImagePickerController alloc] init];
    picker2.delegate = self;
    [picker2 setSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
    [self presentViewController:picker2 animated:YES completion:NULL];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];



}


#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        longditute = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        Latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
    }
    // Stop Location Manager
    [locationManager stopUpdatingLocation];
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

   image = [info objectForKey:UIImagePickerControllerOriginalImage];
   [imageView setImage:image];
   [self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
scb998
  • 899
  • 5
  • 18
  • 42
  • See http://stackoverflow.com/questions/1238838/uiimagepickercontroller-and-extracting-exif-data-from-existing-photos – rmaddy Jan 21 '14 at 23:25
  • @maddy - i have tried to implement this solution, but for some reason they aren't working properly when i implement them. – scb998 Jan 22 '14 at 03:22

0 Answers0