Start to Develop Bing Map Application (2)

2011-07-20


We have finished the first step: Apply a Bing map key to develop Bing map application.

Now we are going to write code for a simple Bing map application. What we first need to do is install Bing map SDK, we have already had an article about Bing map SDK. but the SDK information updated by Microsoft, so please find the newest Bing map SDK from Microsoft official site and download proper SDK package for your application.

For example, if you want to create a Bing map application using Silverlight, you should download Bing map Silverlight controls. The download place is here. After your download, you will find a file named "BingMapsSilverlightControlv1.0.1Installer.msi". double click to install the Bing map SDK.

Now we use Visual Studio 2010, create a new Silverlight Application:

bingMap05

In the project, right click the Silverlight Application’ references folder to Add Reference.

bingMap06

Locate the installing Bing map SDK folder, just like the following:

bingMap07

There are two dll files under the Libraries folder:

Microsoft.Maps.MapControl.Common.dll   
Microsoft.Maps.MapControl.dll

Add these two files as references.

Note: You do not need to download the control if you are only going to use the embedded maps feature or if you want to access the Bing Maps Silverlight Control using JavaScript. These features are described in the Embedding a Map into Your Web Page and the Accessing the Control Using Script topics. – From MSDN

__Open MainPage.xaml, you can see the following code:

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White"></Grid>
</UserControl>

Changed above code to below code:

<UserControl x:Class="SilverlightTestApplication.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
    <Grid x:Name="LayoutRoot" Background="White">
        <m:Map CredentialsProvider="your key" Mode="Aerial" />
    </Grid>
</UserControl>

At once, you will see your Sign windows of Visual studio display a Bing map like the following:

BingDev08

Then, run the application in Visual Studio, you will see the Bing map in web browser.