自动上传GPS位置

时间:2013-10-28 14:09:49

标签: javascript asp.net gps

通常情况下,我更喜欢潜伏在论坛寻找答案,但我找不到一个,所以这里就是......

我有一个自定义车队管理系统,我在ASP为客户编写,他们已经要求GPS功能,以便他们可以摆脱他们的月度卫星服务。我为卡车驾驶室中的笔记本电脑购买了一个串行GPS加密狗,并为卡车司机的笔记本电脑写了一个简短的Windows服务来读取和翻译数据。目前,我每隔10秒用翻译的位置覆盖一个文本文件。 (这样做的原因是Google API显然无法识别Windows 7中的外部位置传感器。)

然而,现在,我需要将该信息发送到服务器,以便可以使用位置更新调度员,以便卡车司机在客户处标记他们的位置,以便其他可能需要覆盖其路线的司机。我想我将不得不使用JavaScript,但希望有人可以向我发送正确的方向。我试图将一个值预填充到一个html文件上传小部件中,但显然这不起作用

或者我可以将文件保存在临时Internet文件中并通过ASP获取吗?使用套接字推送到服务器会更好吗?我想加入我已经写过的网站......

我不需要任何代码,我只需指向正确的方向!

谢谢!

1 个答案:

答案 0 :(得分:0)

好的,明白了。感谢dmarruco建议使用REST,它激发了我对xml使用类似的解决方案。客户端如下:

Imports System.IO
Imports System.IO.Ports
Imports System.Text
Imports System.Xml
Imports System.Web
Imports System.Net


Module Module1

Sub Main()
    Dim myport As SerialPort = New SerialPort("COM3", "4800", Parity.None, 8, StopBits.One)
    Dim availableSerialPorts As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.Ports.SerialPortNames
    If availableSerialPorts.Contains("COM3") Then
        Dim dstring As String = ""
        Try
            If myport.IsOpen Then
                myport.Close()
            End If
            myport.Open()
            System.Threading.Thread.Sleep(1500)
            Dim datastring As String = myport.ReadExisting
            dstring += datastring
            myport.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            If myport IsNot Nothing Then
                myport.Close()
            End If
        End Try

        Dim loc As Integer
        Dim search As String = "$GPGGA"
        loc = InStr(1, dstring, search, CompareMethod.Text)

        Dim latstart As Integer = loc + 18
        Dim lonstart As Integer = loc + 30
        Dim lat As String = Mid(dstring, latstart, 9)
        Dim lon As String = Mid(dstring, lonstart, 10)
        Dim gpgga As String = Mid(dstring, loc, 50)

        If Left(lat, 1) <> "," And Left(lon, 1) <> "?" Then

            Dim HH As String = Left(lat, 2)
            Dim mmmm As String = Mid(lat, 3, 7)
            Dim mconv As String = Val(mmmm) / 60
            mconv = mconv.Replace("0.", "")
            Dim latcoord As String = HH & "." & mconv
            Dim lH As String = Left(lon, 3)
            Dim lmm As String = Mid(lon, 4, 7)
            Dim lmC As String = Val(lmm) / 60
            lmC = lmC.Replace("0.", "")
            Dim loncoord As String = "-" & lH & "." & lmC
            Dim xmldoc As New XmlDocument
            Dim xmldec = xmldoc.CreateXmlDeclaration("1.0", "ASCII", "")
            Dim outx As XmlElement
            outx = xmldoc.CreateElement("Location")
            xmldoc.AppendChild(outx)
            Dim root As XmlElement = xmldoc.DocumentElement
            xmldoc.InsertBefore(xmldec, root)
            Dim xmlat As XmlElement
            xmlat = xmldoc.CreateElement("lat")
            xmlat.InnerText = latcoord
            outx.AppendChild(xmlat)

            Dim xmlon As XmlElement
            xmlon = xmldoc.CreateElement("lon")
            xmlon.InnerText = loncoord
            outx.AppendChild(xmlon)
            Dim machineid As String = "1" 'arbitrary for testing purposes
            Dim xmach As XmlElement
            xmach = xmldoc.CreateElement("MID")
            xmach.InnerText = machineid
            outx.AppendChild(xmach)

            Dim url As String = "http://fakeurl.com/getxml.aspx" 'the receiving page goes here
            Dim wreq As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
            Dim encoding As New ASCIIEncoding()
            Dim bytestowrite As Byte() = encoding.GetBytes(xmldoc.ToString)
            wreq.Method = "POST"
            wreq.ContentLength = bytestowrite.Length
            wreq.ContentType = "text/xml"
            Dim mystream As Stream = wreq.GetRequestStream()
            mystream.Write(bytestowrite, 0, bytestowrite.Length)
            mystream.Close()

        Else
            MsgBox("No Fix")
        End If
    Else
        MsgBox("Disconnected")
    End If
End Sub

End Module

原谅try / catch这是我发布之前的测试代码。