2016-11-10 84 views

回答

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]; 

這裏是蘋果的示例代碼: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; 
    } 
}