2016-11-10 2 views
0

AVAsset (или AVURLAsset) содержит элементы AVMetadataItems в массиве, из которых может быть общий ключ AVMetadataCommonKeyLocation.Преобразование строки GPS в AVMetadataItem в CLLocation

Значение этого элемента является строка, которая отображается в формате, как:

+ 39.9410-075.2040 + 007,371/

Как преобразовать эту строку в CLLocation?

ответ

0

Хорошо, я понял, что строка находится в формате 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; 
    } 
} 
Смежные вопросы