【问题标题】:Find Direction from one Location to another, Where Location defined by Latitude and Longitudes查找从一个位置到另一个位置的方向,其中位置由纬度和经度定义
【发布时间】:2011-07-20 12:35:26
【问题描述】:

我不想要任何代码,但想参考我们如何找到从一个位置到另一个位置的方向 ex.North、South East 或 West,其中两个位置都由纬度和经度定义...

我已经关注了这个Link 并看到了第 5 个答案,但我认为它不像我想要的那样正确......

如果您有任何建议,请帮助我解决我的问题。

提前致谢!!

【问题讨论】:

    标签: iphone objective-c ipad ios4 ios-4.2


    【解决方案1】:

    这只是伪代码,是一个只有字符串的示例,您可以使用 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

    【讨论】:

    • 只检查 else if(p1_lat>p2_lat){ result_lng=@"West"; } 在这个 p1_Lat 还是 p1_Lng?
    【解决方案2】:

    查看CLLocation中的课程对象。

    在那个链接中,我猜currentDirectionLat 方法解决了你的问题。

    【讨论】:

      猜你喜欢
      • 2017-11-10
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      • 2011-09-09
      • 2010-11-28
      相关资源
      最近更新 更多