WPF地图应用开发-----BingMap系列1
准备工作:
1、下载WPF Bingmap 控件 网址:http://www.microsoft.com/en-us/download/details.aspx?id=27165
2、申请 开发者 Key 从这申请 :http://www.bingmapsportal.com/
3、安装WPF BingMaps 控件。
开始:
1、新建WPF工程
2、引用添加 WPF BingMaps 控件 在安装路径 下 找到 dll 如我安装在:C:\Program Files\Bing Maps WPF Control\V1\Libraries\Microsoft.Maps.MapControl.WPF.dll
3、代码:
1 <Window x:Class="BingMapTest.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF" 5 Title="MainWindow" Height="600" Width="800"> 6 <Grid> 7 <m:Map x:Name="map" CredentialsProvider="此处写你申请的Key" Center="XXXXX,XXXXX"/>
<!--Center 属性是初次显示的 显示在地图中心的坐标 --> 9 </Grid> 10 </Window>
ok,现在能显示 一副 英文地图。。。看是 开发中经常 要使用 中文地图,那么 开始看 中文地图怎么搞:
4、加载中文地图
代码:(利用 MapTileLayer类 加载中文版地图。 这是 在构造函数中 运行 此方法)
1 private void AddTileOverlay() 2 { 3 // Create a new map layer to add the tile overlay to. 4 MapTileLayer tileLayer = new MapTileLayer(); 5 // The source of the overlay. 6 TileSource tileSource = new TileSource(); 7 tileSource.UriFormat = "http://r2.tiles.ditu.live.com/tiles/r{quadkey}.png?g=41"; 8 // Add the tile overlay to the map layer 9 tileLayer.TileSource = tileSource; 10 // Add the map layer to the map 11 if (!map.Children.Contains(tileLayer)) 12 { 13 map.Children.Add(tileLayer); 14 } 15 tileLayer.Opacity = 1; 16 }
1 public MainWindow() //构造函数 2 { 3 InitializeComponent(); 4 AddTileOverlay(); //加载中文地图 5 }
ok 现在 可以显示 一副 中文版地图.

浙公网安备 33010602011771号