Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

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

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(@"
Latitude: %@
Longitude: %@",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;

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

i think you should grab the value using following:

 CLLocation *location = [asset valueForProperty:ALAssetPropertyLocation];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...