Click here to Skip to main content
15,860,859 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have the latitude and longitude values and I have to calculate the direction(NE,NW,SE,SW) from it. I have calculated the direction but I always get SE direction. Please guide me how to calculate the direction from latitude and longitude.

I am calculating it on the basis of +ve and -ve value of latitude and longitude. If Latitude is +ve it is in the North direction else in the South direction, same for Longitude if it is +ve the it is in East otherwise in West. e.g: Latitude = 40.6331 and Longitude = -89.3985 so Direction = "NW" Is it the correct way?

Thanks
Posted
Updated 3-Feb-11 18:46pm
v2

You just made a bug. Want to talk about it?

I mean, there are not special instructions how to calculate it — just do it and debug your code step by step. If it does not help (sigh...), well, post your code, the you might get some help.

(Seriously, better do it yourself. But if you decide to post your (failed) code, please update your Question, use "Improve Question".
Important! Do not post an Answer! It will be removed. You can also "Add comment" and reply any existing comment.)

—SA
 
Share this answer
 
v3
Comments
JF2015 4-Feb-11 0:34am    
Good advice to do the obvious - some OP'S must really think we are magicians :)
Sergey Alexandrovich Kryukov 4-Feb-11 4:00am    
Thanks for understanding.
--SA
Where you are getting this lat,lag values.., Normally any GPS unit gives you the data in specific format like NMEA

in that only you will get the directions also

see the below example data for NMEA

GGA - essential fix data which provide 3D location and accuracy data.

 $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47

Where:
     GGA          Global Positioning System Fix Data
     123519       Fix taken at 12:35:19 UTC
     4807.038,N   Latitude 48 deg 07.038' N
     01131.000,E  Longitude 11 deg 31.000' E
     1            Fix quality: 0 = invalid
                               1 = GPS fix (SPS)
                               2 = DGPS fix
                               3 = PPS fix
			       4 = Real Time Kinematic
			       5 = Float RTK
                               6 = estimated (dead reckoning) (2.3 feature)
			       7 = Manual input mode
			       8 = Simulation mode
     08           Number of satellites being tracked
     0.9          Horizontal dilution of position
     545.4,M      Altitude, Meters, above mean sea level
     46.9,M       Height of geoid (mean sea level) above WGS84
                      ellipsoid
     (empty field) time in seconds since last DGPS update
     (empty field) DGPS station ID number
     *47          the checksum data, always begins with *
 
Share this answer
 
Comments
Dot-Net-Dev 4-Feb-11 0:37am    
I am calculating it on the basis of +ve and -ve value of latitude and longitude. If Latitude is +ve it is in the North direction else in the South direction, same for Longitude if it is +ve the it is in East otherwise in West.
e.g: Latitude = 40.6331
and Longitude = -89.3985
so Direction = "NW"
Is it the correct way?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900