2013年9月13日 星期五

[Windows Store] Windows Store App 的Bing Map地區化(localized)

今天在使用Windows Store中的Bing Map時,發現其實Map的標記(map labels)是支援本地化(localized)的,這功能主要是透過設定Map的Culture屬性來指定要本地化的語言,下面用個簡單的範例來說明。

在介面中放上三個可以更換不同語言的button,然後下面則是Bing Map,Xaml代碼如下:
<Page
x:Class="MapTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MapTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Maps="using:Bing.Maps"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Maps:Map x:Name="bingmap" Credentials="Your Key" ZoomLevel="14" Margin="0,143,0,0"/>
<Button Content="zh-Hant" Height="51" Margin="277,50,0,0" Width="157" Click="Button_Click"/>
<Button Content="ko" Height="51" Margin="498,50,0,0" Width="157" Click="Button_Click"/>
<Button Content="ja" Height="51" Margin="695,50,0,0" Width="157" Click="Button_Click"/>
</Grid>
</Page>
view raw MapCulture.xaml hosted with ❤ by GitHub


在程式部分則必須要根據點選到的button來判斷語言,並且更換Culture屬性,這樣當點選到不同語言時,Map就會切換到對應的語系
using Bing.Maps;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace MapTest
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
bingmap.HomeRegion = "US";
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
switch ((sender as Button).Content.ToString())
{
case "zh-Hant":
bingmap.Culture = "zh-Hant";
break;
case "ko":
bingmap.Culture = "ko";
break;
case "ja":
bingmap.Culture = "ja";
break;
}
}
}
}
view raw MapCulture.cs hosted with ❤ by GitHub


Culture為繁體中文
image

Culture為韓文
image

Culture為日文
image

而目前Bing Map所支援的Cultures可以參考下面MSDN文件
Return localized results

0 意見:

張貼留言