1

我的应用程序中有一张地图,但是当它加载时,缩放级别离我的位置很远。

那么如何使地图放大到设备的 excat 位置并显示点,就像使用内置的 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();
    }
}
4

0 回答 0