Click here to Skip to main content
15,921,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I programming application for Windows Mobile 6 devices and i have one problem with my GPS communication. Every time when i want to connect with GPS and get Longitude and Latitude value, my GPS.POSITION is always NOTHING value. Please if any have solution for me. I hope to help me.

Thanks.

My code example is following:

VB
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
Posted
Updated 16-May-12 22:03pm
v2
Comments
Richard MacCutchan 17-May-12 4:09am    
Where, what, how? It is no use dumping your program and expecting other people to fix it for you. Explain clearly where it is going wrong and what is happening.
Bernhard Hiller 18-May-12 2:47am    
Are you really sure that it is position which is null? I'd rather guess that one of the many following conditions is false! Better build your output string step by step from the distinct values, and use a "n/a" if a value is not available.
And by the way, do you have GPS reception in your office where you test your program?!

1 solution

I can't understand you say.Explain clearly where it is going wrong and what is happening.
 
Share this answer
 
Comments
neneiki 17-May-12 6:24am    
Тhis condition always is FALSE because the position is always nothing.
Why the position is always nothing?


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900