Microsoft Surface--Bing™ Maps WPF Control

     最近Bing maps团队为我们带来了Bing™ Maps WPF Control ,现在是Beta 1版本,现在我们可以为Microsoft Surface提供地图开发。

新建项目

Microsoft Surface--Bing™ Maps WPF Control_第1张图片

添加引用

Microsoft Surface--Bing™ Maps WPF Control_第2张图片

Xaml Code:

1  xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF" 

  

BingMaps使用

使用BingMaps前需要注册获得 Bing Maps Key

Xaml Code:

1 <Grid>
2 <m:Map ZoomLevel="2"
3 x:Name="Map" CredentialsProvider="your key goes here">
4 <m:Map.Mode>
5 <m:AerialMode Labels="True" />
6 </m:Map.Mode>
7 <m:Pushpin Location="33.845881352,105.165628188471"></m:Pushpin>
8 </m:Map>
9 </Grid>

  演示:

Microsoft Surface--Bing™ Maps WPF Control_第3张图片

添加定位功能:

Xaml Code:

 1 <Grid>
2 <m:Map ZoomLevel="2"
3 x:Name="Map" CredentialsProvider="your key goes here">
4 <m:Map.Mode>
5 <m:AerialMode Labels="True" />
6 </m:Map.Mode>
7 <m:Pushpin Location="33.845881352,105.165628188471"></m:Pushpin>
8 </m:Map>
9
10 <StackPanel HorizontalAlignment="Right" VerticalAlignment="Center" Width="170" Height="120" Opacity="0.66" Background="Bisque">
11 <TextBlock HorizontalAlignment="Left" Foreground="Red">度:</TextBlock>
12 <TextBox x:Name="tbLongitude" Text="0.0" TextAlignment="Right"></TextBox>
13 <TextBlock HorizontalAlignment="Left" Foreground="Red">纬度:</TextBlock>
14 <TextBox x:Name="tbLatitude" Text="0.0" TextAlignment="Right"></TextBox>
15 <Button Width="80" Height="30" Click="Button_Click">
16 <TextBlock>定位</TextBlock>
17 </Button>
18 </StackPanel>
19 </Grid>

  C# Code:

 private void Button_Click(object sender, RoutedEventArgs e)
        {
            double latitude = 0;
            double longitude = 0;
            double.TryParse(tbLatitude.Text, out latitude);
            double.TryParse(tbLongitude.Text, out longitude);
            this.Map.SetView(new Location(latitude, longitude), 5);
        }

  最后演示:

Microsoft Surface--Bing™ Maps WPF Control_第4张图片

Microsoft Surface--Bing™ Maps WPF Control_第5张图片

好了,就到这里了。

转载时须注明本文的详细链接,否则作者将保留追究其法律责任

出处:http://www.cnblogs.com/flute-di/

作者:王迪

你可能感兴趣的:(Microsoft)