calculate x & y from lat & long

Discussion in 'MFC' started by answerme, Apr 29, 2010.

  1. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    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:
    [B]BOTTOM RIGHT CORDINATES[/B]
    m_fMaxLat = 12.581369; //MAX lat value	
    m_fMaxLon = 77.383798;// Max long value
    
    [B]TOP LEFT CORDINATES[/B]
    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
     
  2. chandu004

    chandu004 New Member

    Joined:
    May 20, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice