AVAsset(或AVURLAsset)包含数组中的AVMetadataItems,其中一个可能是公共密钥AVMetadataCommonKeyLocation。
该项目的值是一个字符串,其格式如下:
+39.9410-075.2040+007.371/
如何将该字符串转换为 CLLocation?
好吧,我发现该字符串是 ISO 6709 格式,然后找到一些相关的 Apple 示例代码后就弄清楚了。
NSString* locationDescription = [item stringValue];
NSString *latitude = [locationDescription substringToIndex:8];
NSString *longitude = [locationDescription substringWithRange:NSMakeRange(8, 9)];
CLLocation* location = [[CLLocation alloc] initWithLatitude:latitude.doubleValue
longitude:longitude.doubleValue];
这是苹果示例代码:AVLocationPlayer
另外,这里是转换回来的代码:
+ (NSString*)iso6709StringFromCLLocation:(CLLocation*)location
{
//Comes in like
//+39.9410-075.2040+007.371/
//Goes out like
//+39.9410-075.2040/
if (location) {
return [NSString stringWithFormat:@"%+08.4f%+09.4f/",
location.coordinate.latitude,
location.coordinate.longitude];
} else {
return nil;
}
}
我正在研究同样的问题,并且我在 Swift 中有相同的代码,但没有使用
substring
:
这里的
locationString
是
+39.9410-075.2040+007.371/
let indexLat = locationString.index(locationString.startIndex, offsetBy: 8)
let indexLong = locationString.index(indexLat, offsetBy: 9)
let lat = String(locationString[locationString.startIndex..<indexLat])
let long = String(locationString[indexLat..<indexLong])
if let lattitude = Double(lat), let longitude = Double(long) {
let location = CLLocation(latitude: lattitude, longitude: longitude)
}