【问题标题】:iPhone App :show direction using MapiPhone App:使用地图显示方向
【发布时间】:2011-09-30 04:14:01
【问题描述】:

在我的 iPhone 应用程序中如何显示从当前位置到终点的路线?

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

【问题讨论】:

标签: iphone objective-c ios4 google-maps gps


【解决方案1】:

如果您的意思是基于两点将用户带到地图应用程序,那么您可以这样做:

  1. 创建一个如下所示的 NSURL: NSURL *URL = [NSURL URLWithString:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"]; 您适当地插入您的起始地址和目的地(经纬度)。
  2. 告诉您的应用程序打开 URL [[UIApplication sharedApplication] openURL:URL];

它应该会自动带您进入地图应用程序!

【讨论】:

  • 当我在 iPhone 5.0 模拟器中运行它时,它会打开 google 地图的 safari 版本。运行这个模拟器和实际设备有区别吗?
【解决方案2】:

试试这个:-

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

【讨论】:

    【解决方案3】:
    NSString *Urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%@&daddr=%@",from_address,to_address];
    
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];
    

    这将给出明确的方向,提及源地址和目标地址。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-09
      • 2011-03-21
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      相关资源
      最近更新 更多