[W8.1]Get speed every second from GPS on all application pages. Windows Store App RRS feed

  • Question

  • The application

    I am trying to make a tablet application which will track the speed and location of a driver. The application only has to work while the screen is opened (it isn't necessary to control what it does while the tablet is in a sleep mode or the screen is simply turned off)

    The problem

    I can't figure out exactly how to make the action run successfully. It works sometimes but it seems it only does so after I have asked information from the GPS a couple times.

    It also seems that WIFI messes with the capability of getting the speed value

    What I have tried

    Here is the code that initializes my Geolocator (situated in the OnLaunched method in the App.Xaml.VB page)

    _geolocator = New Geolocator
    _geolocator.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High
    _geolocator.DesiredAccuracyInMeters = 100
    _geolocator.ReportInterval = 1000 '1 second between updates
    AddHandler _geolocator.PositionChanged, AddressOf Geo_PositionChanged
    AddHandler _geolocator.StatusChanged, AddressOf GeoLoc_StatusChanged 'Subscribe for status changes

    I then have in the App.Xaml.VB page the declaration of the Geo_PositionChanged method.

    Private Sub Geo_PositionChanged(ByVal sender As Geolocator, ByVal e As PositionChangedEventArgs)
            Dim pos As Geoposition = e.Position
            If pos.Coordinate.Speed IsNot Nothing Then
                Speed = pos.Coordinate.Speed.ToString()
                Longitude = pos.Coordinate.Point.Position.Longitude.ToString()
                Latitude = pos.Coordinate.Point.Position.Latitude.ToString()
            End If
        Catch ex As Exception
            strError = ex.ToString()
        End Try
    End Sub

    The Question

    How do I make the application get the GPS data, most importantly the speed, every second (if there is movement detected) ?

    Are there any obvious errors in my code someone could shed a light on ?

    Friday, July 17, 2015 8:16 PM

All replies

  • Does the tablet have gps in it?  If it is just getting the position from wifi I doubt it will be all the accurate of a location.
    Saturday, July 18, 2015 4:11 PM
  • This API needs some hardware support, for speed


    This optional property will be set if it is available. If the property is not available, the value will be NULL or NaN (depending on the operating system version). We recommend that your app checks for both of these possibilities

    Accelerometer Sample: https://code.msdn.microsoft.com/windowsapps/Accelerometer-Sensor-Sample-22982671

    And if your app has turned to Background, the information retrieving process will be paused, see app life cycle

    Best Regards,
    Please remember to mark the replies as answers if they help

    Monday, July 20, 2015 6:56 AM
  • Hey I just wanted to add some clarifications to the problem as it seems I was lacking a few details.

    The tablet respects all requirements and is able to get the speed through e.position (using satellite) as shown in the code above

    My problem is I can't get said speed every second in the app.xaml.vb file.

    The reason I am trying to execute this code in app.xaml.vb is to have the event run across all pages of the application. This means I would avoid having to start it using OnNavigatedTo on each page.

    Monday, July 20, 2015 3:21 PM