如何获得2个地方之间的方向?

时间:2011-11-22 13:18:44

标签: iphone objective-c cocoa-touch ios4

在我的应用中,我想显示两个地方之间的方向。

我得到了Latitude&两个地方的经度。

并希望在此网址中添加该lat,

   NSURL *strlist = [NSURL URLWithString:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"]; 

但是,当我给拉特时,长期喜欢这个,

 NSURL *strlist = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f & daddr=%f,%f",c_lat,c_long,lat,lat]];

// c_lat - 目前的纬度//双格式
// c_long - 当前经度//双格式
// lat - 特殊位置纬度//双格式
// lat - 特殊地方经度//以双重格式

在NSlog中(“URL:%@”,strlist);我得到了NULL值。

如何添加Lat& NSURL很长?

2 个答案:

答案 0 :(得分:3)

删除%f&之间的空格 同样,删除&daddr

之间的空格

应该是这样的

 NSURL *strlist = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",c_lat,c_long,lat,lat]];

答案 1 :(得分:2)

这项工作当您拨打谷歌指导服务时,请尝试此操作,

NSString* url=[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=true",
[NSString stringWithFormat:@"%f,%f",currentLocation.latitude,currentLocation.longitude],[NSString stringWithFormat:@"%f,%f",annotation.coordinate.latitude,annotation.coordinate.longitude]];

感谢,
MAYUR