iOS iPhone无法使用Google地球应用程序打开生成/保存的KML文件

时间:2014-05-25 21:25:30

标签: ios kml uiapplication

使用以下代码我尝试在Google地球应用中打开生成并保存的KML文件。

Google地球应用会打开,但它什么都不做。

当我通过电子邮件发送此文件并使用GE App打开它时,它可以正常工作。 有没有办法从我在GE的应用程序中打开mml?

我尝试打开的网址: KML:/// VAR /移动/应用/的 **** /Documents/google_earth.kml

这里是代码:

    NSError *error;
    BOOL success;

    //get the documents directory:
    NSArray *paths = NSSearchPathForDirectoriesInDomains
    (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *fileNameKML = [NSString stringWithFormat:@"%@/google_earth.kml", documentsDirectory];
    NSString *GoogleEarthfileName = [NSString stringWithFormat:@"kml://%@", fileNameKML];
    //NSLog([NSString stringWithFormat:@"Google Earth filename: %@", GoogleEarthfileName]);

    NSURL *newURL = [NSURL URLWithString:GoogleEarthfileName];
    success = [kmlExport writeToFile:fileNameKML atomically:YES encoding:NSUTF8StringEncoding error:&error];
     if (success){
         if ([[UIApplication sharedApplication] canOpenURL:newURL])
         {
             [[UIApplication sharedApplication] openURL:newURL];
         }
         else
         {
             UIAlertView * alertView = [[[UIAlertView alloc] initWithTitle:@"Google Earth not installed" message:@"Please install Google Earth to view your tracked route." delegate:self cancelButtonTitle:NSLocalizedString(@"TXTOK", nil) otherButtonTitles: nil] autorelease];
             [alertView show];
         }
    }

谢谢Kevin

0 个答案:

没有答案