【原创】从自制的GPS轨迹记录仪中(单片机)中读取数据并显示出来生成Google map的轨迹图的VB6代码

2013-08-06 20:39:32  阅读 2887 次 评论 0 条

这是一段从自制的GPS轨迹记录仪中(单片机)中读取数据并显示出来生成Google map的轨迹图的VB6代码

 

Private Sub Command1_Click()
   ' 保存输入子串的缓冲区
   Dim s As Date
   Dim SS As String
   Dim S1 As String
   ' 使用 COM1。
   MSComm1.CommPort = 3
   ' 9600 波特,无奇偶校验,8 位数据,一个停止位。
   MSComm1.Settings = "9600,N,8,1"
   ' 当输入占用时,
   ' 告诉控件读入整个缓冲区。
   MSComm1.InputLen = 0
   ' 打开端口。
   MSComm1.PortOpen = True
   ' 将 attention 命令送到调制解调器。
   Text1 = ""
   s = Now
   MSComm1.Output = "$READALL|"
   Do
      DoEvents
   'Buffer$ = Buffer$ & MSComm1.Input
   S1 = MSComm1.Input
   SS = SS & S1
   If S1 = "|" Then
        Text1 = Text1 & SS & vbCrLf
        SS = ""
   End If
   Loop Until InStr(SS, "OK")
   ' 从串行端口读 "OK" 响应。

   ' 关闭串行端口。
   MSComm1.PortOpen = False
MsgBox "接收完成! 耗时:" & Format((Now - s) * 24 * 60 * 60, "#,##0.00") & "秒"
End Sub

Private Sub Command2_Click()
Dim Row_l
Dim itmx As ListItem
Dim i As Long
Row_l = Split(Text1, vbCrLf)
ListView1.ListItems.Clear

For i = 0 To UBound(Row_l)
    If Len(Row_l(i)) = 32 Then
        Set itmx = ListView1.ListItems.Add
            itmx.Text = Left(Row_l(i), 2) & "-" & Mid(Row_l(i), 3, 2) & "-" & Mid(Row_l(i), 5, 2)
            itmx.SubItems(1) = Mid(Row_l(i), 7, 2) & ":" & Mid(Row_l(i), 9, 2) & ":" & Mid(Row_l(i), 11, 2)
            '处理+8的时序
            If CDbl(Mid(Row_l(i), 7, 2)) + 8 > 23 Then
                itmx.Text = Format(CDate(Left(Row_l(i), 2) & "-" & Mid(Row_l(i), 3, 2) & "-" & Mid(Row_l(i), 5, 2)) + 1, "yyyy-MM-dd")
                itmx.SubItems(1) = Format(CDbl(Mid(Row_l(i), 7, 2)) - 16, "00") & ":" & Mid(Row_l(i), 9, 2) & ":" & Mid(Row_l(i), 11, 2)
            Else
                itmx.Text = Left(Row_l(i), 2) & "-" & Mid(Row_l(i), 3, 2) & "-" & Mid(Row_l(i), 5, 2)
                itmx.SubItems(1) = Format(CDbl(Mid(Row_l(i), 7, 2)) + 8, "00") & ":" & Mid(Row_l(i), 9, 2) & ":" & Mid(Row_l(i), 11, 2)
            End If
            itmx.SubItems(2) = Mid(Row_l(i), 13, 4) & "." & Mid(Row_l(i), 17, 6)
            itmx.SubItems(3) = Mid(Row_l(i), 23, 3) & "." & Mid(Row_l(i), 26, 6)
    End If
Next
End Sub

Private Sub Command3_Click()
Dim i As Integer
Open App.Path & "\TEMP.KML" For Output As #1   ' 打开输出文件。
Print #1, "<?xml version='1.0' encoding='UTF-8'?>"
Print #1, "<kml xmlns='http://www.opengis.net/kml/2.2' xmlns:gx='http://www.google.com/kml/ext/2.2' xmlns:kml='http://www.opengis.net/kml/2.2' xmlns:atom='http://www.w3.org/2005/Atom'>"
Print #1, "<Document>"
Print #1, "    <Folder>"
Print #1, "        <name>TEMP</name>"
Print #1, "        <open>1</open>"
For i = 1 To ListView1.ListItems.Count
            Print #1, "        <Placemark>"
            Print #1, "            <name>" & "20" & ListView1.ListItems(i).Text & " " & ListView1.ListItems(i).SubItems(1) & "</name>"
            Print #1, "            <Point>"
            Print #1, "                <gx:drawOrder>1</gx:drawOrder>"
            Print #1, "                <coordinates>" & Mid(ListView1.ListItems(i).SubItems(2), 2, 4) & CLng(CLng(Mid(ListView1.ListItems(i).SubItems(2), 6)) / 0.6) & "," & Mid(ListView1.ListItems(i).SubItems(3), 2, 3) & CLng(CLng(Mid(ListView1.ListItems(i).SubItems(3), 5)) / 0.6) & ",0</coordinates>"
            Print #1, "            </Point>"
            Print #1, "        </Placemark>"
Next
Print #1, "    </Folder>"
Print #1, "</Document>"
Print #1, "</kml>"
Close #1
End Sub

Private Sub Form_Load()
ListView1.ColumnHeaders.Add , , "日期"
ListView1.ColumnHeaders.Add , , "时间"
ListView1.ColumnHeaders.Add , , "经度"
ListView1.ColumnHeaders.Add , , "纬度"

End Sub


本文地址:http://blog.jinesc.net/?id=162
版权声明:本文为原创文章,版权归 jinesc 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?