最近使用到Windows Store App中的Bing Map時,因為電腦設定的地區是台灣,而目前台灣不在Bing Map的支援地區中(可以參考文章最後面的MSDN文件所列出目前不支援的國家),所以使用時Map就不會載入任何影像,也就無法進行使用
雖然可以透過控制台的地區設定更換到支援的國家來正常使用,但如果是發佈到Store中的話,就無法去控制使用者設定的國家,也不太可能要使用者在使用前都先切換到支援的國家(使用者就不想用了吧…),所以查了一下,其實可以藉由設定Map控制項的HomeRegion屬性來解決這問題,只要設定成US,那麼不管控制台中的地區設定成哪裡,都可以正常地進行使用。
首先在VS中要使用到Bing Map控制項要先加入相關Reference,還有進行一些設定,步驟與方式可以參考我之前寫的這篇文章,這裡就不再重複
http://www.dotblogs.com.tw/eternaltung/archive/2012/09/12/bingmapsmetrostyleapps.aspx
加入好Bing Map後,可以在Xaml或程式中設定HomeRegion屬性為US,這樣Map的區域就不會受控制台中的區域設定而改變,也就可以正常進行使用了。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Page | |
x:Class="MapTest.BlankPage1" | |
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="41,31,40,56"/> | |
</Grid> | |
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Bing.Maps; | |
using Windows.UI.Xaml.Controls; | |
using Windows.UI.Xaml.Navigation; | |
namespace MapTest | |
{ | |
public sealed partial class MapRegion : Page | |
{ | |
public BlankPage1() | |
{ | |
this.InitializeComponent(); | |
bingmap.HomeRegion = "US"; | |
} | |
protected override void OnNavigatedTo(NavigationEventArgs e) | |
{ | |
} | |
} | |
} |
Reference
Supported Regions
0 意見:
張貼留言