窗口电话中的GPS(当我在途中移动时从当前位置移动。怎么样?)

时间:2012-03-15 06:16:16

标签: geolocation windows-phone bing-maps

我在Windows Phone 7.1中使用GPS,我在bing地图上获得了当前位置,并获得最近的餐馆在bing地图上显示。但现在我想要的是当我继续前进的路上然后我的图钉显示我也随身携带。 即当前的位置也想随着我的运动而改变。

1 个答案:

答案 0 :(得分:0)

我希望this能帮到你。简而言之,您必须使用对象GeoCoordinateWatcher

private void startLocationButton_Click(object sender, RoutedEventArgs e)
{
    if (watcher == null)
    {
        watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
        watcher.MovementThreshold = 20;
        watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
        watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);

    }
    watcher.Start();
}

void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
    switch (e.Status)
    {
        case GeoPositionStatus.Disabled:
            MessageBox.Show("Location Service is not enabled on the device");
            break;

        case GeoPositionStatus.NoData:
            MessageBox.Show(" The Location Service is working, but it cannot get location data.");
            break;
    }
}

void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    if (e.Position.Location.IsUnknown)
    {
        MessageBox.Show("Please wait while your prosition is determined....");
        return;
    }
}