开发者

Problem in getting latitude and longitude in windows phone 7 application

I am using the GeoCoordinateWatcher class to get the latitude and longitude of the windows phone 7, but when I debug this application on my windows phone, I am getting GeoPositionStatus.NoData in my StatusChanged event. Please tell me what is wrong with the following code.

GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
watcher.MovementThreshold = 10.0f;
// wire up event handlers
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_statusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);

void watcher_statusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
    switch (e.Status)
    {
        case GeoPositionStatus.Disabled:
            if (watcher.Permission == GeoPositionPermission.Denied)
            {
                // the user has disabled LocServ on their device.
                statusTextBlock.Te开发者_如何转开发xt = "You have disabled Location Service.";
            }
            else
            {
                statusTextBlock.Text = "Location Service is not functioning on this device.";
            }
        break;

        case GeoPositionStatus.Initializing:
            // The location service is initializing.
            statusTextBlock.Text = "Location Service is retrieving data...";
        break;

        case GeoPositionStatus.NoData:
            // The Location Service is working, but it cannot get location data
            // due to poor signal fidelity (most likely)
            statusTextBlock.Text = "Location data is not available.";
        break;

        case GeoPositionStatus.Ready:
            // The location service is working and is receiving location data.
            statusTextBlock.Text = "Location data is available.";
        break;
    }
}

void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
{
    // update the textblock readouts.
    latitudeTextblock.Text = e.Position.Location.Latitude.ToString("0.0000000000");
    longitudeTextblock.Text = e.Position.Location.Longitude.ToString("0.0000000000");
    speedreadout.Text = e.Position.Location.Speed.ToString("0.0") + " meters per second";
    coursereadout.Text = e.Position.Location.Course.ToString("0.0") + " degrees";
    altitudereadout.Text = e.Position.Location.Altitude.ToString("0.0") + " meters above sea level";
}


You should start the watcher.

watcher.Start(...);


I see that you've discovered that location services was turned off. But something to keep in mind is in certification they will check to see if your program can handle that scenario. When you start Location services you can then see if it is disabled.

watcher.Start(); bool IsLocationServicesTurnedOff = (watcher.Permission == GeoPositionPermission.Denied);

Also remember that in Mango your program can be suspended, location services disabled, and your program reactivated. In other words location services can perceivable be disabled at any time during the life of your program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜