I’ve been looking quite some time today to gather GPS coordinates from a Windows Phone 7 device – however since I do not have an actual test device here I tried to set some dummy data which I want to have returned instead of real GPS Data … that, however ist not working out too well:
This code ist partially an example from so which I found here. However I tried to put it into a class which I can access later.
public class GetGPS : GeoCoordinateWatcher
{
GeoCoordinateWatcher watcher;
public GetGPS()
{
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.MovementThreshold = 20;
watcher.PositionChanged += this.watcher_PositionChanged;
watcher.StatusChanged += this.watcher_StatusChanged;
watcher.Start();
}
private void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
case GeoPositionStatus.Ready:
//plingpling
break;
case GeoPositionStatus.Disabled:
// location is unsupported on this device
break;
case GeoPositionStatus.NoData:
watcher.Position.Location.Latitude = 54.086369f;
watcher.Position.Location.Longitude = 12.124754f;
break;
}
}
private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
var epl = e.Position.Location;
// Access the position information thusly:
epl.Latitude.ToString("0.000");
epl.Longitude.ToString("0.000");
epl.Altitude.ToString();
epl.HorizontalAccuracy.ToString();
epl.VerticalAccuracy.ToString();
epl.Course.ToString();
epl.Speed.ToString();
e.Position.Timestamp.LocalDateTime.ToString();
}
}
This is my other class in which I try to access the data – however I always get NaN as lat1Rad and long1Rad … can you please help me?
I want that example to be functional on the emulator ( with a fixed GPS Coordinate ) and on a phone 7 device – where it actually grabs the value.
GetGPS location1= new GetGPS();
//GeoCoordinate myPosition = location1.getPosition();
//Radianten berechnen
double lat1Rad = GradZuRad(location1.Position.Location.Latitude);
double long1Rad = GradZuRad(location1.Position.Location.Longitude);
I basically just want to program a class which returns me the CURRENT GPS Position.
Where is your example code from?
Have you tried using the sample on MSDN?
Alternatively, there’s a greate simulator available from http://phone7.wordpress.com/2010/08/02/no-device-no-gps-no-matter-with-code/