AVAsset (或AVURLAsset)在数组中包含AVMetadataItems,其中一个可能是公用密钥AVMetadataCommonKeyLocation。
该项的值是以如下格式显示的字符串:
+39.9410-075.2040+007.371/
如何将该字符串转换为CLLocation?
发布于 2016-11-10 02:09:54
好的,我发现字符串是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;
}
}发布于 2020-02-25 14:57:00
我处理相同的问题,并且在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)
}https://stackoverflow.com/questions/40518926
复制相似问题