Click here to Skip to main content
15,898,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following is the code in mapping with gps and C#. Please send an explanation of this block.

C#
private void timer1_Tick(object sender, EventArgs e)
{
    if (serialPort1.IsOpen)
    {
        string data = serialPort1.ReadExisting();
        string[] strArr = data.Split('$');
        for (int i = 0; i < strArr.Length; i++)
        {
            string strTemp = strArr[i];
            string[] lineArr = strTemp.Split(',');
            if (lineArr[0] == "GPGGA")
            {
                try
                {
                    //Latitude
                    Double dLat = Convert.ToDouble(lineArr[2]);
                    dLat = dLat / 100;
                    string[] lat = dLat.ToString().Split('.');
                    Latitude = lineArr[3].ToString() +
                    lat[0].ToString() + "." +
                    ((Convert.ToDouble(lat[1]) /
                    60)).ToString("#####");

                    //Longitude
                    Double dLon = Convert.ToDouble(lineArr[4]);
                    dLon = dLon / 100;
                    string[] lon = dLon.ToString().Split('.');
                    Longitude = lineArr[5].ToString() +
                    lon[0].ToString() + "." +
                    ((Convert.ToDouble(lon[1]) /
                    60)).ToString("#####");

                    //Display
                    txtLat.Text = Latitude;
                    txtLong.Text = Longitude;

                    btnMapIt.Enabled = true;
                }
                catch
                {
                    //Cannot Read GPS values
                    txtLat.Text = "GPS Unavailable";
                    txtLong.Text = "GPS Unavailable";
                    btnMapIt.Enabled = false;
                }
            }
        }
    }
    else
    {
        txtLat.Text = "COM Port Closed";
        txtLong.Text = "COM Port Closed";
        btnMapIt.Enabled = false;
    }
}


Edit TR - Please don't use all caps, it's considered shouting and rude (see the posting guidelines on the right when posting). Also, be more specific, we won't help you if you don't ask a specific question.
Posted
Updated 15-Apr-10 2:54am
v2

This code is fairly trivial, albeit nasty and broken for some cultures.

What part exactly are you having trouble with?

Nick
 
Share this answer
 
It looks first to see if a Serial Port is open. If it is, it reads in the data from the port.

Then, it splits the data and looks for the GPGGA data. It then grabs the Lat/Lon data and displays it.

Seriously, you listed your country as US, so with that assumption, you can read english.

Without any coding knowledge, you should be able to figure this out.


sneha111 wrote:
if (serialPort1.IsOpen)



sneha111 wrote:
data = serialPort1.ReadExisting()



sneha111 wrote:
data.Split('$')



sneha111 wrote:
if (lineArr[0] == "GPGGA")



sneha111 wrote:
//Latitude



sneha111 wrote:
//Longitude



sneha111 wrote:
//Display
txtLat.Text = Latitude;
txtLong.Text = Longitude;
 
Share this answer
 

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