0

AVAsset(或 AVURLAsset)在一个数组中包含 AVMetadataItems,其中一个可能是公共密钥 AVMetadataCommonKeyLocation。

该项目的值是一个字符串,其格式如下:

+39.9410-075.2040+007.371/

如何将该字符串转换为 CLLocation?

4

2 回答 2

1

好的,我发现字符串是 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];

这是 Apple 示例代码: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;
    }
}
于 2016-11-10T02:09:54.673 回答
1

我处理相同的问题,并且在 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)
}
于 2020-02-25T14:57:00.477 回答