当前位置:编程学习 > wap >>

Windows Phone加载BingMaps中文版地图

相信有很多人在开发WP7的时候都用过BM控件
但是作为一个中国人,看着纯英文版的地图,还是觉得有点别扭
所以特意在网上搜了一下方法,然后自己实现出来,现在分享给大家!
首先在XAML代码里添加如下代码

xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
  

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <my:Map x:Name="myMap" HorizontalAlignment="Left" VerticalAlignment="Top"
                    Height="607" Width="456" Margin="0"
                    CredentialsProvider="[LIVEID]"
                    LogoVisibility="Collapsed"
                    CopyrightVisibility="Collapsed"
                    ZoomBarVisibility="Visible"/>

</Grid>
接下来在xaml.cs文件里添加如下代码:
void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            UriBuilder tileSourceUri = new UriBuilder("http://r2.tiles.ditu.live.com/tiles/r{quadkey}.png?g=41");
            MapTileLayer tileLayer = new MapTileLayer();
 
            Microsoft.Phone.Controls.Maps.Platform.Location first = new Microsoft.Phone.Controls.Maps.Platform.Location();
            first.Latitude = 60;
            first.Longitude = 60;
            LocationRectTileSource tileSource = new LocationRectTileSource(tileSourceUri.Uri.ToString(), 
                new LocationRect(first, 180, 180), new Range<double>(1, 16));
 
            tileLayer.TileSources.Add(tileSource);
            tileLayer.Opacity = 0.9;
            myMap.Children.Add(tileLayer);
 
            myMap.Mode = new MercatorMode();
        }

 下面试运行后的效果截图:



源码下载地址如下:/2012/0330/20120330011840641.zip

  
 

摘自  小胡子
补充:移动开发 , Windows Phone ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,