sirishapolsapalli

GeoCoordinateWatcher does not fire PositionChanged/StatusChanged events

Discussion created by sirishapolsapalli on Dec 11, 2012
Hello:

I have been using Garmin GPS 18x USB device to track location with in a WPF application using the System.Device.Location.GeoCoordinateWatcher object.

For the last couple of weeks PositionChanged and StatusChanged events stopped firing recently. Nothing I do make the events fire. They do not fire even when I move the GPS.

I am using Windows 7. When I look at the GeoCoordinateWatcher status it says "NoData" and all the values for the GeoCoordinateWatcher.Position is "NaN".

Any help is greatly appreciated.

Here is the code which I am using to track the GPS position.

void _map_Loaded(object sender, RoutedEventArgs e)

{

System.Device.Location.
GeoCoordinateWatcher geowatcher = new System.Device.Location.GeoCoordinateWatcher(GeoPositionAccuracy.High);

geowatcher.PositionChanged +=
new System.EventHandler<GeoPositionChangedEventArgs<System.Device.Location.GeoCoordinate>>(geowatcher_PositionChanged);

geowatcher.StatusChanged +=


new EventHandler<GeoPositionStatusChangedEventArgs>(geowatcher_StatusChanged);

geowatcher.Start();

}

void geowatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)

{

if (e.Status == GeoPositionStatus.Ready)

{

}

string statuschange = e.Status.ToString();

}

void geowatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)

{

GraphicsLayer gps = this._map.Layers["gpsLayer"] as GraphicsLayer;

if (gps == null) //First Time. Create layer

{

gps =


new GraphicsLayer() { ID = "GPSLYR" };

_map.Layers.Add(gps);

Graphic g = new Graphic() { Symbol = new SimpleMarkerSymbol() };

gps.Graphics.Add(g);

}
var coord = e.Position.Location;
//The course value must be between 0.0 and 360.0, and Double.NaN if the heading is not defined.
double course = e.Position.Location.Course;
MapPoint p = new MapPoint(coord.Longitude, coord.Latitude);

txtLat.Text = coord.Latitude.ToString();

txtLong.Text = coord.Longitude.ToString();

txtCourse.Text = course.ToString();
// Project point to Map???s spatial reference, use ESRI.ArcGIS.Client.Projection.WebMercator or Geometry Service

ESRI.ArcGIS.Client.Projection.

WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
MapPoint geogCenterPoint = null;

geogCenterPoint = mercator.ToGeographic(p)


as MapPoint;



gps.Graphics[0].Geometry = geogCenterPoint;

}


Thank you,

Sirisha.

Outcomes