Imports System.Runtime.InteropServices Imports Microsoft.WindowsMobile.Samples.Location Public Class frmGPSNew Dim updateDataHandler As System.EventHandler = New System.EventHandler(AddressOf UpdateData) Dim gps As New Gps() Dim device As GpsDeviceState = Nothing Dim position As Microsoft.WindowsMobile.Samples.Location.GpsPosition Dim sateliti As Integer Private Sub btnTurnON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTurnON.Click gps.Open() If gps.Opened Then MsgBox("Open") Else MsgBox("Failed to open") End If End Sub Private Sub btnTurnOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTurnOff.Click If gps.Opened Then gps.Close() MsgBox("closed") End If End Sub Private Sub frmGPSNew_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler gps.DeviceStateChanged, AddressOf gps_DeviceState_Changed AddHandler gps.LocationChanged, AddressOf gps_Location_changed End Sub Private Sub gps_Location_changed(ByVal sender As Object, ByVal args As LocationChangedEventArgs) position = args.Position BeginInvoke(updateDataHandler) End Sub Private Sub gps_DeviceState_Changed(ByVal sender As Object, ByVal args As DeviceStateChangedEventArgs) device = args.DeviceState BeginInvoke(updateDataHandler) End Sub Public Sub UpdateData(ByVal sender As Object, ByVal args As System.EventArgs) If gps.Opened Then Dim str As String = "" If device IsNot Nothing Then str = device.FriendlyName End If position = gps.GetPosition() position.GetSatellitesInSolution() sateliti = position.SatelliteCount If position IsNot Nothing Then If position.SeaLevelAltitudeValid AndAlso position.SpeedValid AndAlso position.LatitudeValid AndAlso position.LongitudeValid AndAlso position.SatellitesInSolutionValid AndAlso position.SatellitesInViewValid AndAlso position.SatelliteCountValid AndAlso position.TimeValid Then txtLatitude.Text = "LAT: " & position.Latitude & vbCr & "LONG: " & position.Longitude & vbCr & "Number Satellites: " & position.SatelliteCount & vbCr & "DTE/TME: " & position.Time.ToString() End If End If End If End Sub End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)