相信有很多人在開發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(); }
下面試運行後的效果:
源碼如下:
http://dl.dbank.com/c01t5zidso
另外小弟建了個WP7開發交流QQ群,歡迎部落格的各位大牛、小牛們哈
QQ群號:170716593