📄 gpsposition.vb
字号:
Imports System.Runtime.InteropServices
Namespace Microsoft.WindowsMobile.Samples.Location
Friend Enum FixQuality
Unknown = 0
Gps = 1
DGps = 2
End Enum
Friend Enum FixType
Unknown = 0
XyD = 1
XyzD = 2
End Enum
Friend Enum FixSelection
Unknown = 0
[Auto] = 1
Manual = 2
End Enum
Public Class Satellite
Private m_azimuth As Integer
Private m_elevation As Integer
Private m_id As Integer
Private m_signalStrength As Integer
Friend Sub New()
End Sub
Friend Sub New(ByVal id As Integer, ByVal elevation As Integer, ByVal azimuth As Integer, ByVal signalStrength As Integer)
m_id = id
m_elevation = elevation
m_azimuth = azimuth
m_signalStrength = signalStrength
End Sub
Public Property Azimuth() As Integer
Get
Return m_azimuth
End Get
Set(ByVal value As Integer)
m_azimuth = value
End Set
End Property
Public Property Elevation() As Integer
Get
Return m_elevation
End Get
Set(ByVal value As Integer)
m_elevation = value
End Set
End Property
Public Property Id() As Integer
Get
Return m_id
End Get
Set(ByVal value As Integer)
m_id = value
End Set
End Property
Public Property SignalStrength() As Integer
Get
Return m_signalStrength
End Get
Set(ByVal value As Integer)
m_signalStrength = value
End Set
End Property
End Class
Public Class GpsPosition
Private position As GPS_POSITION
Friend Sub New(ByVal position As GPS_POSITION)
Me.position = position
End Sub
Public Function GetSatellitesInSolution() As Satellite()
Dim inViewSatellites As Satellite() = Me.GetSatellitesInView
Dim list As New ArrayList
Dim index As Integer = 0
Do While (index < Me.position.dwSatelliteCount)
Dim found As Satellite = Nothing
Dim viewIndex As Integer = 0
Do While ((viewIndex < inViewSatellites.Length) AndAlso (found Is Nothing))
If (Me.position.rgdwSatellitesUsedPRNs(index) = inViewSatellites(viewIndex).Id) Then
found = inViewSatellites(viewIndex)
list.Add(found)
End If
viewIndex += 1
Loop
index += 1
Loop
Return DirectCast(list.ToArray(GetType(Satellite)), Satellite())
End Function
Public Function GetSatellitesInView() As Satellite()
Dim satellites As Satellite() = Nothing
If (Me.position.dwSatellitesInView <> 0) Then
satellites = New Satellite(Me.position.dwSatellitesInView - 1) {}
Dim index As Integer = 0
Do While (index < satellites.Length)
satellites(index) = New Satellite
satellites(index).Azimuth = Me.position.rgdwSatellitesInViewAzimuth(index)
satellites(index).Elevation = Me.position.rgdwSatellitesInViewElevation(index)
satellites(index).Id = Me.position.rgdwSatellitesInViewPRNs(index)
satellites(index).SignalStrength = Me.position.rgdwSatellitesInViewSignalToNoiseRatio(index)
index += 1
Loop
End If
Return satellites
End Function
' Properties
Public ReadOnly Property EllipsoidAltitude() As Single
Get
Return Me.position.flAltitudeWRTEllipsoid
End Get
End Property
Public ReadOnly Property EllipsoidAltitudeValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.ALTITUDE_WRT_ELLIPSOID) <> 0)
End Get
End Property
Public ReadOnly Property Heading() As Single
Get
Return Me.position.flHeading
End Get
End Property
Public ReadOnly Property HeadingValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.HEADING) <> 0)
End Get
End Property
Public ReadOnly Property HorizontalDilutionOfPrecision() As Single
Get
Return Me.position.flHorizontalDilutionOfPrecision
End Get
End Property
Public ReadOnly Property HorizontalDilutionOfPrecisionValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.HORIZONTAL_DILUTION_OF_PRECISION) <> 0)
End Get
End Property
Public ReadOnly Property Latitude() As Double
Get
Return Me.position.dblLatitude
End Get
End Property
Public ReadOnly Property LatitudeInDegreesMinutesSeconds() As DegreesMinutesSeconds
Get
Return New DegreesMinutesSeconds(Me.position.dblLatitude)
End Get
End Property
Public ReadOnly Property LatitudeValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.LATITUDE) <> 0)
End Get
End Property
Public ReadOnly Property Longitude() As Double
Get
Return Me.position.dblLongitude
End Get
End Property
Public ReadOnly Property LongitudeInDegreesMinutesSeconds() As DegreesMinutesSeconds
Get
Return New DegreesMinutesSeconds(Me.position.dblLongitude)
End Get
End Property
Public ReadOnly Property LongitudeValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.LONGITUDE) <> 0)
End Get
End Property
Public ReadOnly Property PositionDilutionOfPrecision() As Single
Get
Return Me.position.flPositionDilutionOfPrecision
End Get
End Property
Public ReadOnly Property PositionDilutionOfPrecisionValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.POSITION_DILUTION_OF_PRECISION) <> 0)
End Get
End Property
Public ReadOnly Property SatelliteCount() As Integer
Get
Return Me.position.dwSatelliteCount
End Get
End Property
Public ReadOnly Property SatelliteCountValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.SATELLITE_COUNT) <> 0)
End Get
End Property
Public ReadOnly Property SatellitesInSolutionValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.SATELLITES_USED_PRNS) <> 0)
End Get
End Property
Public ReadOnly Property SatellitesInViewCount() As Integer
Get
Return Me.position.dwSatellitesInView
End Get
End Property
Public ReadOnly Property SatellitesInViewCountValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.SATELLITES_IN_VIEW) <> 0)
End Get
End Property
Public ReadOnly Property SatellitesInViewValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.SATELLITES_IN_VIEW) <> 0)
End Get
End Property
Public ReadOnly Property SeaLevelAltitude() As Single
Get
Return Me.position.flAltitudeWRTSeaLevel
End Get
End Property
Public ReadOnly Property SeaLevelAltitudeValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.ALTITUDE_WRT_SEA_LEVEL) <> 0)
End Get
End Property
Public ReadOnly Property Speed() As Single
Get
Return Me.position.flSpeed
End Get
End Property
Public ReadOnly Property SpeedValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.SPEED) <> 0)
End Get
End Property
Public ReadOnly Property Time() As DateTime
Get
Return New DateTime(Me.position.stUTCTime.year, Me.position.stUTCTime.month, Me.position.stUTCTime.day, Me.position.stUTCTime.hour, Me.position.stUTCTime.minute, Me.position.stUTCTime.second, Me.position.stUTCTime.millisecond)
End Get
End Property
Public ReadOnly Property TimeValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.UTC_TIME) <> 0)
End Get
End Property
Public ReadOnly Property VerticalDilutionOfPrecision() As Single
Get
Return Me.position.flVerticalDilutionOfPrecision
End Get
End Property
Public ReadOnly Property VerticalDilutionOfPrecisionValid() As Boolean
Get
Return ((Me.position.dwValidFields And GPS_VALID.VERTICAL_DILUTION_OF_PRECISION) <> 0)
End Get
End Property
End Class
<StructLayout(LayoutKind.Sequential)> _
Friend Structure GPS_POSITION
Private Const GPS_MAX_SATELLITES As Integer = 12
Public dwVersion As Integer
Public dwSize As Integer
Public dwValidFields As GPS_VALID
Public dwFlags As GPS_DATA_FLAGS
Public stUTCTime As SYSTEMTIME
Public dblLatitude As Double
Public dblLongitude As Double
Public flSpeed As Single
Public flHeading As Single
Public dblMagneticVariation As Double
Public flAltitudeWRTSeaLevel As Single
Public flAltitudeWRTEllipsoid As Single
Public FixQuality As FixQuality
Public FixType As FixType
Public SelectionType As FixSelection
Public flPositionDilutionOfPrecision As Single
Public flHorizontalDilutionOfPrecision As Single
Public flVerticalDilutionOfPrecision As Single
Public dwSatelliteCount As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=12)> _
Public rgdwSatellitesUsedPRNs As Integer()
Public dwSatellitesInView As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=12)> _
Public rgdwSatellitesInViewPRNs As Integer()
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=12)> _
Public rgdwSatellitesInViewElevation As Integer()
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=12)> _
Public rgdwSatellitesInViewAzimuth As Integer()
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=12)> _
Public rgdwSatellitesInViewSignalToNoiseRatio As Integer()
End Structure
<Flags()> _
Friend Enum GPS_VALID
UTC_TIME = 1
LATITUDE = 2
LONGITUDE = 4
SPEED = 8
HEADING = &H10
MAGNETIC_VARIATION = &H20
ALTITUDE_WRT_SEA_LEVEL = &H40
ALTITUDE_WRT_ELLIPSOID = &H80
POSITION_DILUTION_OF_PRECISION = &H100
HORIZONTAL_DILUTION_OF_PRECISION = &H200
VERTICAL_DILUTION_OF_PRECISION = &H400
SATELLITE_COUNT = &H800
SATELLITES_USED_PRNS = &H1000
SATELLITES_IN_VIEW = &H2000
SATELLITES_IN_VIEW_PRNS = &H4000
SATELLITES_IN_VIEW_ELEVATION = &H8000
SATELLITES_IN_VIEW_AZIMUTH = &H10000
SATELLITES_IN_VIEW_SIGNAL_TO_NOISE_RATIO = &H20000
End Enum
<Flags()> _
Friend Enum GPS_DATA_FLAGS
NONE = 0
HARDWARE_OFF = 1
End Enum
<StructLayout(LayoutKind.Sequential)> _
Friend Structure SYSTEMTIME
Friend year As Short
Friend month As Short
Friend dayOfWeek As Short
Friend day As Short
Friend hour As Short
Friend minute As Short
Friend second As Short
Friend millisecond As Short
End Structure
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -