locked
How to deploy GPS application on Windows Mobile 6 RRS feed

  • Question

  • 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:

    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

    • Moved by Mike Feng Wednesday, May 16, 2012 10:26 AM Phone (From:.NET Base Class Library)
    Tuesday, May 15, 2012 2:58 PM

Answers

  • Hi Neneki,

    Please ask this question on Windows Phone forum: http://create.msdn.com/en-US/ 

    Thank you for your understanding and support.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Mr. Wharty Thursday, May 31, 2012 3:42 AM
    • Marked as answer by Just Karl Sunday, September 22, 2013 3:02 PM
    Wednesday, May 16, 2012 10:26 AM

All replies

  • Hi Neneki,

    Please ask this question on Windows Phone forum: http://create.msdn.com/en-US/ 

    Thank you for your understanding and support.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Mr. Wharty Thursday, May 31, 2012 3:42 AM
    • Marked as answer by Just Karl Sunday, September 22, 2013 3:02 PM
    Wednesday, May 16, 2012 10:26 AM
  • Hi, this is my code, and is run OK

    Imports System
    Imports System.Drawing
    Imports System.Collections
    Imports System.Windows.Forms
    Imports System.Data
    Imports Microsoft.WindowsMobile.Samples.Location
    Public Class Form1
        Dim device As GpsDeviceState = Nothing
        Dim position As GpsPosition = Nothing
        Dim gps As New Gps

        'Private updateDataHandler As EventHandler
        Dim updateDataHandler As System.EventHandler = New System.EventHandler(AddressOf UpdateData)


        Private Sub btnCapturar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapturar.Click
            If gps.Opened = False Then
                gps.Open()
            End If
        End Sub

        Private Sub BtnCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCerrar.Click
            If gps.Opened = True Then
                gps.Close()
            End If

        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        
            AddHandler gps.DeviceStateChanged, AddressOf gps_DeviceStateChanged
            AddHandler gps.LocationChanged, AddressOf gps_LocationChanged
        End Sub

        Protected Sub gps_LocationChanged(ByVal sender As Object, ByVal args As LocationChangedEventArgs)
            position = args.Position
            Invoke(updateDataHandler)
        End Sub

        Sub gps_DeviceStateChanged(ByVal sender As Object, ByVal args As DeviceStateChangedEventArgs)
            device = args.DeviceState
            Invoke(updateDataHandler)
        End Sub

        Sub UpdateData(ByVal sender As Object, ByVal args As System.EventArgs)
            If gps.Opened = True Then
                If device Is DBNull.Value = False Then
                    'str = device.FriendlyName + " " + device.ServiceState + ", " + device.DeviceState + "\n";
                End If

                If position Is DBNull.Value = False Then
                    If position.LatitudeValid = True Then
                        lblLatitud.Text = position.Latitude
                    End If
                    If position.LongitudeValid = True Then
                        lblLongitud.Text = position.Longitude
                    End If
                End If
                If position.SatellitesInSolutionValid And position.SatellitesInViewValid And position.SatelliteCountValid Then
                    lblSatelites.Text = "Satelites: " & position.SatelliteCount
                End If
                If Val(lblLatitud.Text) <> 0 And Val(lblLongitud.Text) <> 0 And position.PositionDilutionOfPrecision > 0 And position.PositionDilutionOfPrecision < 3 Then
                    '                gps.Close()
                    MsgBox("Finalizado")
                End If
            End If
        End Sub
    End Class

    Wednesday, July 17, 2013 8:45 PM