捕获照片的GPS位置和存储的图像

时间:2014-01-21 23:18:20

标签: ios gps uiimagepickercontroller

我正在创建一个应用程序,允许用户拍照或从照片卷中选择一个,并通过电子邮件发送到特定地址。但是,以下代码有效,如果有人拍照,然后在发送电子邮件之前移动,则GPS位置不准确。

我有办法吗?

  • 拍照,存放Lat&照片被带到变量的地方很长
  • 从照片卷轴中选择一张照片,提取lat& long,并存储到变量

这是我的代码:

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

0 个答案:

没有答案