GPSLayer Position

2992
5
02-25-2013 03:07 AM
JohanWennberg1
New Contributor
Hi

Im using a SerialPortGPSCoordinateWatcher to receive GPS signals from a USB GPS device which i connect to a GPSLayer.

It works fine, i retrieve signals and GeoCoordinates but the position property of my GPSLayer is null? Do i have to do anything special to retrieve the Map position of the GPSLayer? I also have a valid spatialreference on my map.

Cheers
/Johan
0 Kudos
5 Replies
TomGiles
New Contributor
Hi Johan,

I am having the same problem, and have run into a wall. Did you ever find a solution to this?

Cheers
Tom
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Please you post a snippet of your code to help ascertain what might be the issue?

Cheers

Mike
0 Kudos
TomGiles
New Contributor
Hi,

I just solved it, a rather silly mistake. I was simply accessing the position too early; once accessed through the Position_Changed event I can access it.

I do have a follow-up question for you Mike:

When accessing the GeoPositionWatcher I see some of the methods, eg:
  Console.WriteLine(gpsLayer.GeoPositionWatcher.Position.Location.HorizontalAccuracy.ToString)

but not all as seen in the Advanced GPS Information sample, eg:
  <TextBlock Text="{Binding Position.Location.FixStatus
  <TextBlock Text="{Binding Position.Location.FixSatelliteCount
  <TextBlock Text="{Binding Position.Location.CourseMagnetic
  <TextBlock Text="{Binding Position.Location.GeoidHeight

I realize you bind to those properties in XAML. I can only access Altitude, Course, Speed, Lat, Long and the horiz and vert accuracies. I am looking for FixSatelliteCount.

Can I access them code side, from the Position_Changed function?


Thanks,
Tom
0 Kudos
TomGiles
New Contributor
To further my last post, this is the code I am using to create the gpsLayer, and code for Position_Changed, where I try and access the properties I mentioned (those which I seem unable to access). Am I going about this the wrong way?

Public Class GpsTool
 Private gpsLayer As GpsLayer
 Private _locationWatcher As IGeoPositionWatcher(Of Geocoordinate)
 Private _isStarted As Boolean


'in sub New()
Public Sub New(map As Map)
 gpsLayer = New GpsLayer()


'when button is pressed for gps-on
Private Sub gpsButtonClick...
 _isStarted = True
 ThreadPool.QueueUserWorkItem(DirectCast(Sub() CreateGpsWatcher(ESRI.ArcGIS.Client.Local.Gps.SerialPortGpsCoordinateWatcher.FindEnabledPort(1)), WaitCallback))


Private Sub CreateGpsWatcher(serialPorts as List(Of String))
 'dispatcher code

 'if device found
 _locationWatcher = New ESRI.ArcGIS.Client.Local.Gps.SerialPortGpsCoordinateWatcher() With {
  .portName = serialPorts(0) _
 }

 'geometry service for projections

 gpsLayer.GeoPositionWatcher = _locationWatcher
 gpsLayer.GeoPositionWatcher.Start()

 AddHandler gpsLayer.PositionChanged, AddressOf gpsPosition_Changed



'Then in gpsPosition_Changed - this is where I am accessing the properties of the gpsLayer, such as:
Private Sub gpsPosition_Changed(sender As Object, args As EventArgs)
 Console.WriteLine(gpsLayer.GeoCoordinate.Altitude.ToString)



It is in that last function that I do not see the properties that you guys have used in the sample app, through XAML.

Thanks again for any light people can shed on this.

Cheers
Tom
0 Kudos
TomGiles
New Contributor
Still working on this..

Recent development - the tooltip on my GpsPositionWatcher showed it as being from System.Device.Location.GeoCoordinate, not gpsLayer.GeoCoordinate

This reference is from the ArcGIS API for WPF (not runtime api)
"By default the position watcher used is Windows Phone's built-in System.Device.Location.GeoCoordinateWatcher. Overriding this makes it possible to assign a simulator instead."

Do I need to override the default GeoCoordinateWatcher to gain access to all the gpsLayer properties?

(The true GPS seems to be working, it's accurate within a couple meters.)

Thanks
Tom
0 Kudos