Using Bing Maps in a Windows 8 Metro style app

The recently released Bing Maps controls for Windows 8 (available in the Visual Studio Gallery) actually contains two separate map controls to support the two types of Windows 8 applications. One is a port of our existing Javascript map control and is used to write html/javascript applications, the other is written in native C++ and is usable by any Xaml application whether it's using C#, VB.NET, or C++. We've helpfully included a template to make it easy to get started with the Xaml control. Once the Bing Maps SDK for Metro style apps is installed there will be a Bing Maps Application template available under the Visual C#.

It's also easy enough to use Bing Maps in an application from scratch. First add a Reference to Bing Maps for C#, C++, or Visual Basic (Beta) and Microsoft Visual C++ Runtime Package (if you're writing a managed app, C++ only needs Bing Maps).

If you try to build at this point you'll be presented with a most confusing set of error messages:

  • Could not find SDK "Microsoft.VCLibs, Version=11.0".
  • "APPX" attributes were found in the SDK manifest file however none of the attributes matched the targeted configuration and architecture and no "APPX" attribute without configuration and architecture could be found. If an appx is required then the project will fail at runtime.
  • The referenced component 'Microsoft Visual C++ Runtime Package' could not be found.

Don't be alarmed. This just means you're writing a managed application and have left the platform target at the default Any CPU and both Bing Maps and Visual C++ Runtime require a specific architecture to be set. Change the Active solution platform to x64 or x86 and then it will build properly. The Visual C++ Runtime package is required to deploy on computers that do not have Visual Studio installed. To use the Map control you can drag it from the Toolbox and drop it on your page or declare it yourself with the following two snippets:

xmlns:bm="using:Bing.Maps"

<bm:Map Width="800" Height="600" Credentials="INSERT_YOUR_BING_MAPS_KEY" />

You will need a Bing Maps Key to use the map but fortunately we have generous pre-release licensing terms that permit you to use it for free during the beta period. You can read more the licensing terms on the Bing Maps blog. For digging deeper we have also worked hard to make sure the documentation is helpful and up to date.