如何在我的应用程序iOS6中获取驾驶方向

如何在我的应用程序iOS6中获取驾驶方向,ios6,maps,mkmapview,mapkit,apple-maps,Ios6,Maps,Mkmapview,Mapkit,Apple Maps,我在我的应用程序中使用Apple Map,在我的视图中,我想显示从用户位置到视图中当前位置的驾驶方向,现在我只想在我的应用程序中显示所有这些,即我可以在地图视图中显示驾驶方向,我曾尝试使用apple map应用程序,但在我从应用程序中调用它后,它会将我带到apple的map应用程序,在那里我可以获得驾驶方向,但我无法返回到我的应用程序中,因此我认为我可以在应用程序本身中做一些事情,以便我可以在当前视图中获得驾驶方向 NSString* addr = [NSString stringWithFor

我在我的应用程序中使用Apple Map,在我的视图中,我想显示从用户位置到视图中当前位置的驾驶方向,现在我只想在我的应用程序中显示所有这些,即我可以在地图视图中显示驾驶方向,我曾尝试使用apple map应用程序,但在我从应用程序中调用它后,它会将我带到apple的map应用程序,在那里我可以获得驾驶方向,但我无法返回到我的应用程序中,因此我认为我可以在应用程序本身中做一些事情,以便我可以在当前视图中获得驾驶方向

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];
此代码将我从我的原生应用程序带到苹果地图应用程序,但我无法直接返回到我的应用程序。是否有可能的解决方案,以便我在获得驾驶方向后返回到我的应用程序??(webview对我不起作用。我可以在苹果的应用程序上添加一个后退按钮吗?或者什么)。请帮助。。。。非常感谢

或者,有谁能建议我一个更好的代码来实现,这样我就可以在我的应用程序中完成所有这些


我想要一张应用程序内地图,描绘导航路线和驾驶方向…

这应该可以让您开始。简而言之,从google api获取json格式的驱动指令,解析它,并使用
MKPolyline

这不是实现方向的方法

我为您制作了一个样本,涵盖了所有iOS版本、新的谷歌地图和iOS 6的汤姆地图

这是:

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

你是指ios4(你已经标记了)还是iOS6(你已经问了)?@Craig:很抱歉,这是我在标记时的一个输入错误。是的,我觉得iOS6更有可能。在这种情况下,你必须小心在非谷歌地图上使用谷歌的数据。这违反了他们的TOS,虽然我不知道他们是否或如何实施,但最好避免激怒他们。@Craig:是的,我会尽量避免使用它。你有没有链接,这样会很有帮助。.无论如何,谢谢你的帮助。干杯!!如果niks2000真的意味着iOS6,那么在苹果地图上使用谷歌的驾驶方向不是一个(合法的)选项。我只使用苹果的地图,而不是谷歌的。如果你有任何关于这方面的链接,那将非常有帮助。.无论如何,thxs为你提供帮助。干杯!!Thxs很多…@sree charan它对我有用,只是有点变化。Thxs!!