我在我的应用程序中使用 Apple Map,并且在我的 View 中我想显示从用户位置到我在 View 中当前位置的驾驶方向,现在我只想在我的应用程序中显示所有这些,即我可以显示驾驶方向在 map View 上,我曾尝试使用苹果 map 应用程序,但是在我从我的应用程序调用它之后,它会将我带到苹果的 map 应用程序,在那里我获得了行驶方向,但我无法返回到我的应用程序中,所以我在想我可以在我的应用程序中做一些事情,这样我就可以在我当前的 View 中获得行车路线。

NSString* addr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",coordinate.latitude,coordinate.longitude,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];
        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];

此代码将我从 native 应用程序带到苹果的 map 应用程序,但我无法直接返回到我的应用程序。是否有可能的解决方案,以便我可以在获得驾驶方向后返回我的应用程序? (webview 对我不起作用。我可以在苹果的应用程序上添加一个后退按钮还是什么)。请帮忙......非常感谢!

或者请有人建议我一个更好的实现代码,以便我只能在我的应用程序中完成所有这些?

我想要一个描述导航路线和行车路线的应用内 map ...

最佳答案

这不是实现方向的方法,

我为您制作了一个示例,其中涵盖了所有 iOS 版本、新 Google map 和 iOS 6 汤姆猫 map 。

这里是:

if([[[UIDevice currentDevice] systemVersion] compare:@"6.0" options:NSNumericSearch] == NSOrderedDescending){
        //6.0 or above
        NSString *Destinationlatlong =[NSString stringWithFormat:@"%@,%@",your.latitude,your.longitude];

        NSString* addr = [NSString stringWithFormat:@"comgooglemaps://?saddr=%f,%f&daddr=%@",[AppDelegate zDelegate].location.coordinate.latitude,[AppDelegate zDelegate].location.coordinate.longitude, Destinationlatlong];
        addr=[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL* url = [[[NSURL alloc] initWithString:addr]autorelease];
        //    NSLog(@"url %@",url);
        if ([[UIApplication sharedApplication]canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }else{
            CLLocationCoordinate2D coords =
            CLLocationCoordinate2DMake([your.latitude doubleValue],[your.longitude doubleValue]);
            MKPlacemark *placeMark = [[MKPlacemark alloc]
                                      initWithCoordinate:coords addressDictionary:nil];


            MKMapItem *destination = [[MKMapItem alloc]initWithPlacemark:placeMark];

            [destination openInMapsWithLaunchOptions:nil];
        }
    }else{
        NSString *Destinationlatlong =[NSString stringWithFormat:@"%@,%@",your.latitude,your.longitude];
        NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=Current+Location&daddr=%@",Destinationlatlong];
        addr=[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL* url = [[[NSURL alloc] initWithString:addr]autorelease];
        //    NSLog(@"url %@",url);
        if ([[UIApplication sharedApplication]canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }else{
            UIAlertView *alert=[[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Device does not support this functionality" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles: nil]autorelease] ;
            [alert show];
        }
    }

关于ios6 - 如何在我的应用程序 iOS 6 中获取行车路线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14812725/

10-12 16:27
查看更多