【发布时间】:2011-07-20 12:35:26
【问题描述】:
我不想要任何代码,但想参考我们如何找到从一个位置到另一个位置的方向 ex.North、South East 或 West,其中两个位置都由纬度和经度定义...
我已经关注了这个Link 并看到了第 5 个答案,但我认为它不像我想要的那样正确......
如果您有任何建议,请帮助我解决我的问题。
提前致谢!!
【问题讨论】:
标签: iphone objective-c ipad ios4 ios-4.2
我不想要任何代码,但想参考我们如何找到从一个位置到另一个位置的方向 ex.North、South East 或 West,其中两个位置都由纬度和经度定义...
我已经关注了这个Link 并看到了第 5 个答案,但我认为它不像我想要的那样正确......
如果您有任何建议,请帮助我解决我的问题。
提前致谢!!
【问题讨论】:
标签: iphone objective-c ipad ios4 ios-4.2
这只是伪代码,是一个只有字符串的示例,您可以使用 int 代码 (1-8) 每个方向
p1_lat=initial_point.getLatitude();
p1_lng=initial_point.getLongitude();
p2_lat=final_point.getLatitude();
p2_lng=final_point.getLongitude();
NSString result=@"";
NSString result_lat=@"";
NSString result_lng=@"";
NSString result_aux=@"";
if(p1_lat<p2_lat){
result_lat=@"North";
}else if(p1_lat>p2_lat){
result_lat=@"South";
}
if(p1_lng<p2_lng){
result_lng=@"East";
}else if(p1_lng>p2_lng){
result_lng=@"West";
}
if(result_lat!=""&&result_lng!=""){
result_aux="-"
}
result=[result_lat stringByAppendingString(result_aux)];
result=[result stringByAppendingString(result_lng)];
return result;
编辑:“else if”已修复,感谢 Mehul,这是一个复制和粘贴问题:P
【讨论】:
查看CLLocation中的课程对象。
在那个链接中,我猜currentDirectionLat 方法解决了你的问题。
【讨论】: