将当前位置映射到Google地图中的目标位置

时间:2011-07-09 18:18:30

标签: iphone ios4 google-maps nsurl

我的注释上有一个按钮,可以按如下方式调用谷歌地图。 我正在尝试将路线从我已知的当前位置映射到从注释记录传递的目标位置。

当前位置无法在Google地图中识别,而是建议像Current,Dent,Missouri这样的随机地点。

- (IBAction)GoogleMap
{
  NSString *mapAddress = [NSString stringWithFormat:@"%@, %@, %@, %@",location.address, location.city, location.state, location.zipcode];

  NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%@",  
                 // 40.7406578, -74.0020894, test coordinates
                 [mapAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

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

}

知道我哪里错了吗?这不行吗?感谢。

1 个答案:

答案 0 :(得分:0)

据我所知,在Google地图中输入“当前位置”实际上并不会将您发送到您当前的位置。

我建议您使用the method from this SO question获取当前位置,然后将坐标从CLLocation对象传递到Google地图。