0

I do not want any code but want to get reference that how can we find the direction ex.North,South East or West from one location to another location, Where both locations defined by Latitude and Longitudes...

I had followed this Link and see 5th answer but I think It is not as right as I want...

Please if you do have any suggestion then help me to solve my problem.

Thanks in advance !!

Community
  • 1
  • 1
Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94

2 Answers2

2

this is just pseudo-code, and is a sample with just strings, you can use a int code (1-8) for each direction

        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;

Edit: "else if" fixed, thanks Mehul, is a copy&paste problem :P

Anonimo
  • 97
  • 5
1

Look at course object in CLLocation.

In that link, the method currentDirectionLat solves ur problem I guess.

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55