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

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

问题描述:

我在我的应用程序和我的视图中使用Apple Map,我想显示从用户位置到当前位置的驾驶方向,现在我只想要所有这一切只在我的应用程序即ie我可以显示在mapview上的驾驶方向,我曾尝试使用苹果地图应用程序,但我从我的应用程序调用它后,它需要我到苹果的地图应用程序,我得到的驾驶方向,但我不能返回回我的应用程序,所以我想,我可以做我的应用程序本身的东西,这样我可以得到我的当前视图自己的行车路线..如何获取我的应用程序内的驾驶方向iOS6

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

这段代码带我到苹果的地图应用程序从我的本地应用程序,但我不能直接返回到我的app.is有一个可能的解决方案,以便我可以回到我的APP后,获取驾驶方向? (webview没有为我工作。我可以在苹果的应用程序或什么添加一个后退按钮)。请帮助....非常感谢!

或者请任何人都可以给我一个更好的代码来实现,以便我可以在我的应用程序中完成所有这些操作?

我想一个在应用程序的地图描绘导航路线和行车路线...

+0

你的意思是iOS4的(你已经标记)或iOS6的(你问过)? – Craig 2013-02-11 19:30:56

+0

@克雷格:对不起,在我的身边加上拼写错误。 – nikesh 2013-02-12 04:17:04

+0

是的,我认为iOS6更有可能。在这种情况下,您必须小心在非Google地图上使用Google的数据。这违背了他们的服务条款,虽然我不知道他们是否或如何执行它,但最好避免让他们失望。 – Craig 2013-02-12 09:07:03

这不是实现方向的路上自己的地图显示出来,

我已经做了一个样本你可以覆盖所有的iOS版本,新的谷歌地图和iOS 6 tom tom地图。

这就是:

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

Thxs很多... @ sree charan它为我工作了一点点change.Thxs! – nikesh 2013-02-13 12:59:17

这应该让你开始。总之,在得到JSON从谷歌API驱动指示,分析它,并使用MKPolyline http://iosguy.com/2012/05/22/tracing-routes-with-mapkit/

+0

如果niks2000真的意味着iOS6,那么在苹果地图上使用Google的行车路线不是(合法的)选项。 – Craig 2013-02-11 19:31:45

+0

我只与苹果的地图工作,而不是与谷歌的。如果你有任何链接,那么这将是非常有益的..thxs的帮助anyhow.cheers! – nikesh 2013-02-12 03:53:02