0

I've got a key from http://www.bingmapsportal.com and I've added the following code to my project, as demonstrated all over the web.

In the .xaml file:

my:Map Height="320" HorizontalAlignment="Stretch" Name="map1" VerticalAlignment="Top" CredentialsProvider="fa0bb238-62bb-41b9-a1e6-459a5e9564a6"/>

(Key has been slightly edited to avoid abuse)

In the .xaml.cs file:

map1.CredentialsProvider = new ApplicationIdCredentialsProvider("fa0bb238-62bb-41b9-a1e6-459a5e9564a6");
GeocodeRequest gReq = new GeocodeRequest();
GeocodeServiceClient gSrvc = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

gReq.Credentials = new Credentials();
gReq.Credentials.ApplicationId = "fa0bb238-62bb-41b9-a1e6-459a5e9564a6".ToUpper();

gReq.Query = address;

FilterBase[] filters = new FilterBase[2];
filters[0] = new ConfidenceFilter() { MinimumConfidence = Confidence.High };

GeocodeOptions gOpt = new GeocodeOptions();
gOpt.Filters = filters;
gReq.Options = gOpt;

gSrvc.GeocodeCompleted += new EventHandler<GeocodeCompletedEventArgs>(gSrvc_GeocodeCompleted);
gSrvc.GeocodeAsync(gReq);

But I can't get it to work, I'm getting an invalid credentials message on the map itself, and an Invalid Credentials exception with the server's response on the GeocodeRequest.

I've visited around 20 forum topics (including WP7 Bing Maps 'Invalid Credentials' Error) and I seem to have done everything they're talking about or have posted as a solution.

Any other ideas?

Community
  • 1
  • 1

1 Answers1

2

Here is how i initialize a GeocodeRequest in WP7:

GeocodeService.GeocodeRequest request = new GeocodeService.GeocodeRequest
{
    Culture = CultureInfo.CurrentUICulture.ToString(),
    Credentials = new GeocodeService.Credentials { ApplicationId = applicationId },
    UserProfile = new GeocodeService.UserProfile { DeviceType = GeocodeService.DeviceType.Mobile },
    Options = new GeocodeService.GeocodeOptions { Count = 1 },
    Query = address,
};

As you can see i don't do ToUpper() on the ApplicationId string, but i'm setting the UserProfile (and also the Culture) property. Perhaps the UserProfile.DeviceType = Mobile setting must correspond to the type of your Bing Map API key, which is certainly Mobile, too.

Maybe this is somehow helpful.

Clemens
  • 123,504
  • 12
  • 155
  • 268
  • I've set the DeviceType both in my code and my Bing Maps Account to mobile, and still get the same error on the response. Problem is, I can't even get the simple map to work with the key that site gives me, it tells me that I'm using invalid credentials and to register for a developer account or something. Switching my key to Developer (which doesn't change the key, mind you) doesn't fix that either. ToUpper was just there to test if that was the issue, removing it doesn't help or change anything. – Lefteris Aslanoglou Feb 06 '12 at 21:27
  • Kalispera Lefteris, my bing maps key is a 64-character string like `AnF3BcjKhOj.........................................EdVSnpRIdagJ`, yours looks like a GUID. Are you really using the proper key? – Clemens Feb 06 '12 at 21:35
  • That's what I've been seeing all over the web and it's baffled me. Where have you acquired that 64-character string? Is it not at BingMapsPortal.com using the Create Key on the left side? – Lefteris Aslanoglou Feb 06 '12 at 23:26
  • This is what my Create and View keys page looks like: http://postimage.org/image/a4bx2tdhh/ – Lefteris Aslanoglou Feb 06 '12 at 23:36
  • Well, my page looks the same, but your key really looks strange. Is it an option for you to register at Bing Maps Account Center with another Live ID (i.e. another email address) and create another key? Otherwise you should contact the MS guys at the email they state on that page (mpnet@microsoft.com) and tell them about your problem. – Clemens Feb 06 '12 at 23:44
  • I'll try with another live account. Thanks. – Lefteris Aslanoglou Feb 07 '12 at 00:37
  • I've marked your post as the answer, even though your original post didn't have something I had initially tried. You did help me however, verify my code for completeness. **And as it turns out, using another Live account seemed to get me a correctly formatted API key this time.** Don't know why my first account got a GUID-like one; I have no idea actually. Thanks for the tips. – Lefteris Aslanoglou Feb 07 '12 at 00:51