Bing地图,显示一个点+缩放到用户的位置,windows phone

时间:2012-04-05 10:13:27

标签: c# windows-phone-7 bing-maps

我的应用中有一张地图,但是当它加载时,缩放级别远远超出了我的位置。

那么如何让地图放大到设备的激励位置并显示点,就像使用内置的bing贴图一样。

public location()
{
    InitializeComponent();
    map1.ZoomBarVisibility = Visibility.Visible;          
}

private GeoCoordinateWatcher loc = null;

private void map1_Loaded(object sender, RoutedEventArgs e)
{
    loc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
    //EventHandler for location service status changes
    loc.StatusChanged += loc_StatusChanged;
    //If the location service is disabled or not supported
    if (loc.Status == GeoPositionStatus.Disabled)
    {
        //Display a message
        MessageBox.Show("Location services must be enabled");
        return;
    }
    loc.Start();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    loc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
    //EventHandler for location service status changes
    loc.StatusChanged += loc_StatusChanged;
    //If the location service is disabled or not supported
    if (loc.Status == GeoPositionStatus.Disabled)
    {
        //Display a message
        MessageBox.Show("Location services must be enabled");
        return;
    }

    loc.Start();
}

void loc_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
    if (e.Status == GeoPositionStatus.Ready)
    {
        map1.SetView(loc.Position.Location, 10.0);
        loc.Stop();
    }
}

0 个答案:

没有答案