VB实现GPS卫星定位及地图显示 Google Earth

原创 2011年01月07日 17:46:00

你是否看过电影里那高科技呢?当军方在搜索恐怖分子的时候经常会通过卫星定位或手机信号定位到其精准的地理位置,现在使用Google Earth和Google Maps提供的接口,你也可以实现这样的功能,误差距离不超过20米(取决于GPS的等级)

 

首先你需要安装Google Earth,并且确保网络畅通。为了保证刷新的频率不要太高,我们使用Timer定时刷新页面,时间为10s。

 

 

最后的效果如图显示,关于GPS指令请查阅相关资料。

Public Class Form1
    Dim buf As String
    Dim txtbuf(15) As String
    Dim NSEW As String
    Dim APPGE As New EARTHLib.ApplicationGE
    Dim SGE As New EARTHLib.SearchControllerGE

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.SerialPort1.Open()
        Me.CheckForIllegalCrossThreadCalls = False
        buf = ""
        Me.Show()
        GetGoogleSnapHost()
    End Sub

    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        On Error Resume Next
        Me.txtbuf = Nothing
        buf = buf & Chr(Me.SerialPort1.ReadByte)
        If Strings.Right(buf, 2) = Chr(13) & Chr(10) Then
            If Strings.Left(buf, 6) = "$GPGGA" Then
                txtbuf = Strings.Split(buf, ",")
                Me.TextBox1.Text = Me.txtbuf(1)
                Me.TextBox2.Text = Me.txtbuf(2)
                Me.TextBox3.Text = Me.txtbuf(3)
                Me.TextBox4.Text = Me.txtbuf(4)
                Me.TextBox5.Text = Me.txtbuf(5)
                Me.TextBox6.Text = Me.txtbuf(6)
                Me.TextBox7.Text = Me.txtbuf(7)
                Me.TextBox8.Text = Me.txtbuf(8)
                Me.TextBox9.Text = Me.txtbuf(9) & Me.txtbuf(10)
                Me.TextBox10.Text = Me.txtbuf(11) & Me.txtbuf(12)
                If txtbuf(6) = "1" Then
                    NSEW = Me.GetGoogleEartAddr(Me.txtbuf(2), Me.txtbuf(4))
                    Me.TextBox11.Text = NSEW

                End If
               

            End If
            Me.AxiLedRoundX1.Active = Not Me.AxiLedRoundX1.Active
            buf = ""
            Me.SerialPort1.Close()
            Me.SerialPort1.Open()
        End If
    End Sub

    Public Function GetGoogleEartAddr(ByVal opt1 As String, ByVal opt2 As String) As String
        Dim dtmp(4) As Double
        dtmp(0) = Int(Val(opt1) / 100)
        dtmp(1) = (Val(opt1) / 100 - dtmp(0)) * 100 / 60
        dtmp(2) = Int(Val(opt2) / 100)
        dtmp(3) = (Val(opt2) / 100 - dtmp(2)) * 100 / 60
        Return dtmp(0) + dtmp(1) & "," & dtmp(2) + dtmp(3)
    End Function

    Public Sub GetGoogleSnapHost()
        Me.APPGE.SaveScreenShot("F:/GoogleMapsTmp.jpg", 100)
        While Not IO.File.Exists("F:/GoogleMapsTmp.jpg")
            Application.DoEvents()
        End While
        For i = 0 To 1000
            Application.DoEvents()
        Next
        Dim img As Image
        Dim bufdata() As Byte
        bufdata = FileIO.FileSystem.ReadAllBytes("F:/GoogleMapsTmp.jpg")
        Dim wo As New IO.MemoryStream(bufdata)
        img = Image.FromStream(wo)
        Me.Panel1.BackgroundImage = img
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        GetGoogleSnapHost()
        SGE.Search(Me.NSEW)

        Me.WebBrowser1.Navigate("")
        For i = 0 To 100
            Application.DoEvents()
        Next
        Me.WebBrowser1.Document.Write(Me.TextBox12.Text.Replace("31.8063916666667,121.660626666667", Me.NSEW))
        For i = 0 To 100
            Application.DoEvents()
        Next
        Me.WebBrowser1.Refresh()
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)

    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Me.ProgressBar1.Value += 10
        If Me.ProgressBar1.Value = 100 Then Me.ProgressBar1.Value = 0
    End Sub
End Class

 

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

VB中实现地图操作的方法

1.       在VB的Form设计时,加入一个picturebox控件,这个控件作为OLE容器,MapInfo中的地图将在该控件上显示。2.       执行VB的函数Crea...

VB6.0 google 地图显示GPS数据

硬件是由艾琳科技提供的UM220测试板,软件是参考艾琳科技提供是工程文件编写的。硬件我就不介绍了,介绍下软件。 软件是用VB6.0 编写的,用到了其中的WEBBROWERS和MSCOMM控件。工...

C#完整的通信代码(点对点,点对多,同步,异步,UDP,TCP),多多宜善。

C# code namespace UDPServer { class Program { staticvoid Main(string[] args) ...

使用HTML页面美化WinForm窗体

对于大多数的Windows Form桌面表单程序员来说,一直都会希望开发出美观的用户界面。这经常会让我们感到头疼,因为使用GDI或GDI+都需要做很多的事情,今天我在此介绍一种简单便捷且可以让你创作出...

VB.NET C#实现基于UDP的免服务器局域网多客户端点对点通讯

相信很多人都用过类似飞秋的软件,过去也做过很多局域网的数据传输应用,但要么就是基于TCP的,要么就是需要用户设置对方IP的,需要用户对计算机网络及IP地址参数有一定的认知能力。 所以抽时间我重新封装...

GuiPing图形化网络测试

GuiPing帮助       1. 关于GuiPing工具 虽然在Windows平台下有着非常方便的命令行Ping测试工具,但也有着它的局限性,如: (1)进行连续ping时无法查看最大值、最...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)