简体   繁体   English

如何获取已拍摄照片或已拍摄照片的位置(经度/纬度)

[英]How do I get the location (lat/lng) of a picture taken or a picture already taken

This may seem like a duplicate but the Assets Library framework (the current framework most answers are using for the same question) is deprecated as of iOS 9.0 as shown by apples developer docs. 这似乎是重复的,但是如苹果开发人员文档所示,自iOS 9.0起不推荐使用Assets Library框架(大多数答案用于同一问题的当前框架)。

What I need to be able to do is get the lat/lng from a photo which is either currently being taken or a photo which has previously been taken (on a iOS 5+ device as it has location tagging). 我需要做的是从当前正在拍摄的照片或以前已拍摄的照片中获取经纬度(在具有位置标记的iOS 5+设备上)。 Some sample code would be great 一些示例代码会很棒

Thanks 谢谢

Try this 尝试这个

NSData* pngData =  UIImageJPEGRepresentation(image, 1.0);

CGImageSourceRef mySourceRef = CGImageSourceCreateWithData((CFDataRef)pngData, NULL);

if (mySourceRef != NULL)
{
    NSDictionary *myMetadata = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex(mySourceRef,0,NULL);
    NSDictionary *GPSDictionary = [myMetadata objectForKey:(NSString *)kCGImagePropertyGPSDictionary];

    NSLog([GPSDictionary valueForKey:(NSString*)kCGImagePropertyGPSLongitude]);
    NSLog([GPSDictionary valueForKey:(NSString*)kCGImagePropertyGPSLatitude]);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM