WP7 Bing Maps 'Invalid Credentials' Error

2019-02-17 12:34发布

问题:

I'm trying to use a bing maps control on a windows phone 7 silverlight application and it shows this error overlaid on the map.

Invalid Credentials, Sign up for a Developer Account

I've tried using app IDs from these two sites: http://www.bing.com/developers, and https://www.bingmapsportal.com/

am I doing something wrong? is there some account setting that I'm missing? For reference, here's how I'm defining the control and interacting with it:

<my:Map x:Name="MyMap" CredentialsProvider="<<myAppId>>"  />

And in the code behind:

var vm = this.DataContext as ItemViewModel;
Pushpin pushpin = new Pushpin();
Location location = new Location()
{
    Latitude = vm.Latitude,
    Longitude = vm.Longitude
};
pushpin.Location = location;

MyMap.ZoomLevel = 15;
MyMap.Center = location;
MyMap.Children.Add(pushpin);

回答1:

Go to http://bingmapsportal.com and sign in with your Windows Live ID. Once signed in, click Create or view keys in the menu on the left. If you haven't already, create an application by entering the name, URL, and selecting a type (Mobile). Once you've got your application created, copy the long string of characters and paste it into your XAML as the value of the CredentialsProvider attribute.

<my:Map CredentialsProvider="NOTREALVF7QTW-LZfG0p7-RhSPeGvlfx3fdtgR-Gk_SB-wfF8kCj2J7nI57wjIna" />


回答2:

After much travail, I finally discovered that this occurs (at least on desktop SL; not sure about WP7) when the Thread.CurrentUICulture is set to the invariant culture. Be sure it is set to a specific culture (consider also setting Thread.CurrentCulture) in the App.Startup event handler, e.g.

System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

You do still need AppID set, of course.