VB.NET 中嵌入Google earth 并实现gps实时定位

用到了Google earth api 和VB,NET 

VB code如下

Imports System 
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.IO.Ports
Imports System.Text.RegularExpressions

Public Class frmpp
    ' Local variables used to hold the present
    ' position as latitude and longitude
    Public x As String = ""
    Public y As String = ""
    Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
        Try
            SerialPort1.Open() '打开串口
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Timer1.Enabled = True

            btnupdate.Text = "stop"

        End Try



        ' update button label
        If btnupdate.Text = "Update" Then
            btnupdate.Text = "Stop Updates"
        Else
            btnupdate.Text = "Update"
        End If

    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("file:///D:\u\复件 readgps/earth1.htm")
        
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim str As String  '卫星数据
        str = ""
        Dim gpgga_split As String  '分解后gpgga集合
        str = SerialPort1.ReadExisting
        Dim splitresult(), split_gga() As String
        Dim stringelement, GGA_lat, GGA_lng As String
        splitresult = Split(str, vbCrLf)
        For Each stringelement In splitresult 'stringElement 是分解后的单条卫星格式数据
            
            If Regex.IsMatch(stringelement, "^\$GPGGA", RegexOptions.IgnoreCase) And stringelement.Length > 68 Then ' 元素中是否有$GPGGA开始的语句
                gpgga_split = stringelement ' 将GPGGA语句赋予公共变量GPGGA_SPLIT
                split_gga = Split(gpgga_split, ",") ' 以逗号作为分隔符,将GGA语句分离
                GGA_lat = split_gga(2) ' 分割的字段2为 纬度数据
                GGA_lng = split_gga(4) ' 分割的字段4为 经度数据
                x = CDbl(GGA_lat.Substring(0, 2)) + CDbl(GGA_lat.Substring(2, 7)) / 60 ' 转换为度 
                y = CDbl(GGA_lng.Substring(0, 3)) + CDbl(GGA_lng.Substring(3, 7)) / 60 ' 
                txtlat.Text = x
                txtlong.Text = y
                WebBrowser1.Document.All("latitude").InnerText = x ’将纬度的值传给网页
                WebBrowser1.Document.All("longitude").InnerText = y '将精度的值传给网页
                WebBrowser1.Document.GetElementById("submit").InvokeMember("click") ’出发javascript的定位函数
            End If




        Next
        
    End Sub


End Class
运行效果:

1,待机状态:



2运行效果:



javascript 代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <head>
    <title>Google Earth Plug-in</title>
    <!-- NOTE: replace the key below with your own key -->
    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
    <script type="text/javascript">
    google.load('earth', '1');

    var ge = null;
	var x;
	var y;

    function init() {
      google.earth.createInstance('map3d', initCallback, failureCallback);
    }

    function initCallback(pluginInstance) {
      ge = pluginInstance;
      ge.getWindow().setVisibility(true);
      
      // tell the application the plugin is ready
      //.external.JSInitSuccessCallback_(pluginInstance);
    }

    function failureCallback(error) {
      window.external.JSInitErrorCallback_(error);
    }
    
    function lookat(){

var lookAt = ge.createLookAt('');
x = document.getElementById("latitude").value;
y = document.getElementById("longitude").value;
// Set the position values.
lookAt.setLatitude(parseFloat(x));
lookAt.setLongitude(parseFloat(y));

lookAt.setRange(100.0); //default is 0.0

// Update the view in Google Earth.
ge.getView().setAbstractView(lookAt);
}
 
   

    </script>
    <style type="text/css">
    html, body {
      margin: 0;
      width: 100%;
      height: 100%;
    }
    </style>
  </head>
  <body οnlοad="init()">

    <div id="map3d" style="height: 600px; width: 800px;"></div>
<input value=36 id="latitude" />经度
<input value=118 id="longitude" />纬度
<input type="button" id="submit" οnclick="lookat()" value="查看">
  </body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值