calculate x & y from lat & long

answerme's Avatar, Join Date: Dec 2007
Ambitious contributor
I am getting GPS data on my window
Actual GPS DATA is stored in these 2 variables
Code:
float landlong= 77.384547E //Realtime Longtitude
float landlat = 12.583857N   //RealTime Latitude
But it seems the lat & long which iam getting from GPS is not coming inside window, its out of window .I checked x & y cordinates it is
Code:
xPos = 1415.7537		
yPos = -167.81079
the width & height of my window is
Code:
m_WndWidth=1099
m_WndHeight=673
The formula which iam using to calclulate x & y cordinates is

Code:
xPos = (landlong - m_fMinLon) * (m_WndWidth / (m_fMaxLon - m_fMinLon)) ;
yPos = (landlat - m_fMinLat)  * (m_WndHeight / (m_fMaxLat - m_fMinLat)) ;
Code:
BOTTOM RIGHT CORDINATES
m_fMaxLat = 12.581369; //MAX lat value	
m_fMaxLon = 77.383798;// Max long value

TOP LEFT CORDINATES
m_fMinLat = 12.583361;//Min lat value	
m_fMinLon = 77.381506;//min long value
Does anyone has the proper formula to calculate X & Y cordinates

Thanks in advance
0
chandu004's Avatar, Join Date: May 2010
Newbie Member
your formula seems to be alright. but your point is getting displayed beyond the screen display area. to solve this, you need to map (or scale in other words) the start and end co ordinates of your map with your display area, and also you should scale every gps point you are displaying wrt the screen co ordinates.
long back, i also faced the same problem, and i solved it this way.
feel free to mail me, for any further queries.
chandu004@yahoo.com