问题描述
以下是与gps和C#映射的代码.请发送此块的说明.
Following is the code in mapping with gps and C#. Please send an explanation of this block.
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;
}
}
编辑TR-请不要使用所有大写字母,这被认为是喊叫和粗鲁的行为(发布时请参阅右侧的发布指南).另外,更具体而言,如果您不提出特定问题,我们将不会为您提供帮助.
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.
推荐答案
编辑TR-请不要使用所有大写字母,这被认为是喊叫和粗鲁的行为(发布时请参阅右侧的发布指南).另外,更具体地讲,如果您不提出特定问题,我们将不会为您提供帮助.
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.
if(serialPort1.IsOpen)
if (serialPort1.IsOpen)
data = serialPort1.ReadExisting()
data = serialPort1.ReadExisting()
data.Split(''
data.Split(''
这篇关于使用GPS和C#映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!