Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Get The Correct Latitude and Longitude From An Uploaded iPhone Photo?

Tags:

ios

iphone

mapkit

My problem actually seems rather silly... I am writing an iPhone application that uses MKMapKit. The app grabs the EXIF metadata from a provided geotagged photo. The problem is that the latitude and longitude coordinates that I retrieve, for example:

Lat: 34.25733333333334

Lon: 118.5373333333333

returns a location in China. Is there a regional setting that I am missing or do I need to convert the lat/long coordinates before using them?

Thank you all in advance for any help you can provide.

Here is the code I am using to grab the GPS data. You'll notice I am logging everything to the console so I can see what the values are:

void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *) = ^(ALAsset *asset)
{
    NSDictionary *metadata = asset.defaultRepresentation.metadata;
    NSLog(@"Image Meta Data: %@",metadata);
    NSDictionary *gpsdata = [metadata objectForKey:@"{GPS}"];
    self.lat = [gpsdata valueForKey:@"Latitude"];
    self.lng = [gpsdata valueForKey:@"Longitude"];
    NSLog(@"\nLatitude: %@\nLongitude: %@",self.lat,self.lng);
};

NSURL *assetURL = [mediaInfo objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
         resultBlock:ALAssetsLibraryAssetForURLResultBlock
        failureBlock:^(NSError *error) {
        }];

UIImage *img = [mediaInfo objectForKey:@"UIImagePickerControllerEditedImage"];
previewImage.image = nil;
self.previewImage.image = img;

NSData *imageData = UIImagePNGRepresentation(img);
if ([imageData length] > 0) {
    self._havePictureData = YES;

}
like image 649
Leachy Peachy Avatar asked Feb 16 '12 21:02

Leachy Peachy


People also ask

How do I find the latitude and longitude of a photo?

Find the GPS Coordinates In Windows, all you have to do is right-click a picture file, select “Properties,” and then click the “Details” tab in the properties window. Look for the Latitude and Longitude coordinates under GPS.

How do I take location data from a picture?

To find an image's exif data, right-click the photo and select either “properties” or “information”. If the GPS coordinates appear, simply type them into Google Maps to find the location.


2 Answers

i think you should grab the value using following:

 CLLocation *location = [asset valueForProperty:ALAssetPropertyLocation];
like image 112
Allen Avatar answered Oct 24 '22 22:10

Allen


Are you sure you're not missing a minus sign on that 118? 34.257, -118.5373 is nicely inside Los Angeles, California.

like image 28
Tim Avatar answered Oct 24 '22 22:10

Tim