2011-09-30 111 views
0

我的iPhone应用程序如何显示从当前位置到终点的路线?iPhone应用程序:使用地图显示方向

是否有任何内置的组件或设施在iphone上可以显示地图和方向使用GPS和内置指南针?

+0

参考这些链接 http://stackoverflow.com/questions/1944710/google-maps-api-driving-directions http://stackoverflow.com/questions/5102286/iphone-谷歌地图方向 希望这会有所帮助。 –

+0

如果我想通过使用MKMap在我的应用程序中显示此指示,该怎么做。!? – 2011-11-06 21:33:31

回答

5

如果你的意思是采取用户基于两点地图应用程序,那么你可以做这样的:在您的起始地址 NSURL *URL = [NSURL URLWithString:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"]; 您插入:

  1. 创建一个看起来像这样的NSURL和目的地(以经纬度为单位)。
  2. 告诉你的应用程序中打开URL [[UIApplication sharedApplication] openURL:URL];

它应该会自动把你的地图应用程序!

+0

当我在iPhone 5.0模拟器中运行它时,它会打开Safari地图的Safari版本。运行此模拟器与实际设备是否有区别? – x89a10

+0

不是我所知道的,但我可能是错的。 – Mason

0

试试这个: -

NSString *urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%f,%f&daddr=%f,%f",sourcelocation.latitude,sourcelocation.longitude,destinationlocation.latitude,destinationlocation.longitude]; 

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]]; 
0
NSString *Urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%@&daddr=%@",from_address,to_address]; 

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]]; 

这将给予明确的方向提的源地址和目的地址。

相关问题