Getting Started with Bing Maps Silverlight Control v1.0

12. November 2009

BingMapsRTW_BasicMapIt’s been 8 months since the CTP release of the Bing Maps Silverlight Control at MIX’08, and finally this week Microsoft released the Final v1.0 release of the control to the web.  Now, we can all finally start using the Bing Maps Silverlight Control in Production!

If you’ve worked with the CTP, then you’ll want to take a look at Ricky’s “Migrating from Bing Maps Silverlight CTP to Production Version” article. It explains all the stuff you’ll need to modify within your project in order to gracefully switch from the CTP to the v1 Map Control.

Now for those of you who haven’t worked with the CTP…

Where to Start?

First you’ll need to make sure you have the following Tools installed:

Of course you’ll also need to at least be familiar with the basics of Silverlight development. I’m mostly referring to XAML, so if your familiar with WPF that should be enough to get you started.

For those Bing Maps (formerly Virtual Earth) developers new to Silverlight; If you need a little help getting started learning the basics, here are some resources that will help you get started:

Now that you have all the necessary tools installed, you can go ahead and download and install the Bing Maps Silverlight v1 Control.

Download: Bing Maps Silverlight Control SDK Version 1.0

The installer will install the Bing Maps Silverlight Control within the “Program Files” on your computer, along with an SDK Documentation Help (.chm) file.

If you would like to see the Bing Maps Silverligth Control “In Action” and see the source code that powers each example, then you’ll want to check out the Bing Maps Silverlight Control Interactive SDK.

Display a Basic Map

Create a New Silverlight Application Project
  • Run VIsual Studio 2008 and Create a New Project using the Silverlight Application template.
    BingMapsRTW_CreateSilverlightProject
  • In the “Add Silverlight Application” dialog box, select “Host the Silverlight application in a new Web site” option and click “OK”. You must select this option to create an ASP.NET Web Application Project, ASP.NET Website, or ASP.NET MVC Website because the URL Access Restrictions in Silverlight require the page that hosts the Map control be hosted using HTTP in order to load/access the Map TIle Imagery.
    BingMapsRTW_CreateHostWebsite 
Add a Reference to Microsoft.Maps.MapControl.dll
  • Go to the “Solution Explorer” and RIght-Click “ References” in the Silverlight Project (not the ASP.NET Web Application Project), and Select “Add Reference…
    BingMapsRTW_AddReference 
  • Within the “Add Reference“ Dialog, Select the “Browse“ tab and navigate to the folder where the SDK is installed, then select the “Microsoft.Maps.MapControl.dll” and “Microsoft.Maps.MapControl.Common.dll” files.

    Note: Be Default the SDK is installed in this folder on x64 version of Windows: “C:\Program Files (x86)\Bing Maps Silverlight Control\V1\Libraries”. On x86 (or 32-bit) versions of Windows it’s installed within the “Program Files” folder instead of “Program Files (x86)”.

    BingMapsRTW_AddReferenceBrowse 
Display a Bing Maps Map!
  • Add a Namespace declaration to Page.xaml for the Microsoft Maps.MapControl namespace.
    To do this add the following to the <UserControl> tag:
    xmlns:m=”clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl”
  • Add the Map Control to the Page by adding the following tag within the Grid in the Page:
    <m:Map></m:Map> The resulting Page.xaml will look like this:
    <UserControl x:Class="BingMapsSilverlightApplication1.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" 
        xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
        <Grid x:Name="LayoutRoot">
            <m:Map></m:Map>
        </Grid>
    </UserControl>
    Now, when you run the application (press F5 within Visual Studio) you will see a fully interactive Bing Maps map displayed.
    BingMapsRTW_BasicMap

BingMapsRTW_BasicMapWithDevAccountSignUpWarningSetting Up a Bing Maps Developer Account

When running the above example you may have noticed the “Invalid Credentials. Sign up for a developer account at: http://www.microsoft.com/maps/developers” message being displayed over top of the Map. This is because in order for you to use the Silverlight Map control within an application, Microsoft is requiring you to setup a Developer Account for the domain you will be hosting your application in.

Setup a Bing Maps Developer Account
  • Go to the Bing Maps Account Center at https://www.bingmapsportal.com
  • Click the “Create an Account” link on the left side of the site.
  • Sign in with your Windows Live ID
  • Enter it the required Account Details
Get a Bing Maps Key
BingMapsRTW_CreateBingMapsKey
  • Once you have created a Bing Maps Developer Account, just click the “Create or view keys” link on the left side of the Bing Maps Account Center website.
  • Type in some Application Name. This is your name for the application.
  • Type if the Application URL. This is the domain name that you will be hosting the application at.
  • Click the “Create key” button. Now you have a Bing Maps Key that you can use within your application to get rid of that pesky little warning message displayed over the top of the Map and everything on it.
    Note: For testing purposes I entered in an Application Name of “Test” and Application URL of “http://localhost”. This way I have a Bing Maps Key to use for testing/playing with the Silverlight Map Control that wont track any usage to the application I’ll eventually build.
Use the Bing Maps Key within Your Application

Now that you have a Bing Maps Key for your application, you can set your Map within that application to use this key.

To do so, just set the Map controls “CredentialsProvider” property value within XAML to the Bing Maps Key. Just copy and paste the key from the Bing Maps Account Center into your XAML code.

<UserControl x:Class="BingMapsSilverlightApplication1.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" 
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <m:Map CredentialsProvider="[Bing Maps Key Here]"></m:Map>
    </Grid>
</UserControl>

 

Set Map Properties Declaratively Using XAML and Programmatically Using Code

You can change/set the Bing Maps Controls properties Declaratively using XAML, and Programmatically using Code.

Below is an example of setting the Map Mode to Aerial using XAML:

<UserControl x:Class="BingMapsSilverlightApplication1.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" 
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <m:Map Mode="Aerial"></m:Map>
    </Grid>
</UserControl>

 

Below is an example of setting the Map Mode to Aerial using C# code:

using System.Windows.Controls;
using Microsoft.Maps.MapControl;

namespace BingMapsSilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            Map1.Mode = new AerialMode();
        }
    }
}

 

First, in order to access the Map Control programmatically you’ll need to assign its “Name”  property within XAML so you have a name to reference it by; like the following:

<UserControl x:Class="BingMapsSilverlightApplication1.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" 
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <m:Map Name="Map1"></m:Map>
    </Grid>
</UserControl>

 

Additional Articles

Here are some links to additional articles on using the Bing Maps Silverlight Version 1.0 Control:

Conclusion

It’s pretty exciting that we now have a Bing Maps Silverlight control to use within our applications, and finally there is an option other than the JavaScript Control that has far superior performance when plotting over just a couple hundred Pushpins. Plus the Silverlight controls bring the full power of Silverlight to Bing Maps development; which allows for much richer mapping applications to be built.

Keep an eye out, I’ll be posting more articles/tutorials to help you out in exploring this shiny, new Bing Maps Silverlight Control.

Bing Maps, C#, Silverlight , , ,



Comments

11/20/2009 7:27:42 PM #
Bing Maps Silverlight control 1.0 released and handy links

Bing Maps Silverlight control 1.0 released and handy links
11/21/2009 1:14:36 AM #
Thanks for this article, is the best i have found on the web. We got our our Silverlight map control working very quickly using this article.

Now we just need to learn everything we can do. Would be great to read articles on how to find a location from a post code or address, set a push pin in the map, maybe plan a route from the users address to the push pin, show the nearest push pins to that user etc....All things I am sure will run really slick in Silverlight...
12/5/2009 2:36:45 AM #
Pretty Interesting post. Couldnt be written any better. Thanks for sharing!
Alex
Alex
12/5/2009 6:18:05 AM #
I already emailed this question to mpnet@microsoft.com, sorry if it will be seen as a double post...

Here is my stupid problem.

I created a test app BingMapTest1.Web to play with Bing Maps Silverlight Control, following the walk-through in the control's help, but whatever key I use, I get the "invalid credentials" message.

To run the debug build, I created the following key:

    variant #1:
    Application name: BingMapTest1.Web
    Application URL: http://localhost:63802/Default.aspx

Nope, debug build, when run, complains about "invalid credentials"

I installed this app in IIS as http://localhost/BingMapTest1 and tried two other key variants:

    variant #2:
    Application name: BingMapTest1
    Application URL: http://localhost/BingMapTest1

and, exactly as pietschsoft.com/.../..._Control_Version_1_RTW.aspx suggests,

    variant #3:
    Application name: BingMapTest1
    Application URL: http://localhost

which, in my opinion, should not work - http://localhost is the server, not a full URI.

Same thing - "invalid credentials" in all three cases.

What is the simple thing that I am missing?

Any help will be appreciated, because of 5 licenses I spent 3 already.

Thanks in advance.
12/9/2009 3:00:41 PM #
Never seen such cool post. I read it all the way to the end. Keep them coming.
12/10/2009 10:51:18 AM #
Thats an interesting post. It was worth visiting your blog. Hope to visit again.
12/11/2009 7:45:45 AM #
WOW your page came up first in Google. And this is what I was looking for.
12/11/2009 1:31:46 PM #
Yea nice Work !Laughing
12/11/2009 1:43:51 PM #
i really appreciate this your good article
from there i get something that i want to know
thanks for this usefull informations
12/12/2009 12:27:13 PM #
Looks like an interesting blog. Will make visit again.
12/12/2009 2:54:32 PM #
Hi There, It seem blog doesnt display nicely in ie6.
12/13/2009 1:40:06 AM #
Loved reading this post.
12/13/2009 11:57:47 AM #
Bing Maps for Enterprise Developer Resources

Bing Maps for Enterprise Developer Resources
Eric Robishaw
Eric Robishaw
12/15/2009 8:09:09 AM #
What if you want to put the Map Control in a WPF application or WPF Control Library? (vs a Silverlight app)?

Actually (as convoluted as this may be), I want to put the control in a Control that is in a WPF Control Library which will be hosted in a Winform Application.  Am I seeking the impossible?

I've searched all over the web and found no examples or discussions of hosting the Map Control in a WPF Application. Surely there's a use for such, right?



12/16/2009 11:55:00 PM #
Although I do agree with your post, I have my own reservations.
12/21/2009 4:11:53 PM #
Valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up
12/28/2009 2:35:18 PM #
Merry Christmas admin and a Happy New Year. I will be coming back to read more of your interesting post
12/30/2009 1:19:34 AM #
Thank you for your help!
12/30/2009 5:29:04 AM #
I like your blog so much that I feel I have to wish you. Happy New Year in advance. Have a nice and prosperous year ahead
1/1/2010 5:41:57 PM #
Thanks for sharing.. its very good article for the start. i follow u ;)
1/5/2010 6:49:56 PM #
Keep up the good work bro.Your article is really great and I truly enjoyed reading it.Waiting for some more great articles like this from you in the coming days.
1/6/2010 9:49:43 AM #
You write very interestingly. I think Google is becoming very smart. It can sense which website has interesting posts Smile
1/9/2010 12:14:15 PM #
How is the new year going? I hope to read more interesting posts like last year
1/12/2010 5:30:23 PM #
You write very well. Kept me really engaged for some time Smile
1/15/2010 5:57:25 AM #
Great post.keep posting us this type of wonderful information.We always look forward towards your post.
1/15/2010 2:32:32 PM #
Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.
1/15/2010 8:10:44 PM #
Intimately, the post is actually the best on this laudable topic. I harmonize with your conclusions and will eagerly look forward to your future updates. Saying thanks will not just be adequate, for the fantastic lucidity in your writing.
1/15/2010 8:57:21 PM #
This is indeed a great post, I would surely love to know more about it. I will look forward to see more posts from your side.
1/17/2010 11:36:36 AM #
I was wondering what is up with that weird gravatar??? I know 5am is early and I'm not looking my best at that hour, but I hope I don't look like this! I might however make that face if I'm asked to do 100 pushups. lol
1/17/2010 3:46:34 PM #
How-do-you-do, just needed you to know I have added your site to my Google bookmarks because of your extraordinary blog layout. But seriously, I think your site has one of the freshest theme I've came across. It really helps make reading your blog a lot easier.
1/23/2010 2:26:33 AM #
Amazing posts you got in your blog. Will visit again.
1/28/2010 5:27:20 PM #
This is one of the best post I have ever read, I would love to read more in future. Keep up the good work.

1/28/2010 6:18:21 PM #
Nice site. I have enjoyed your site a lot. I want to know more about this. I hope I will get it soon.
1/29/2010 3:33:11 AM #
The desire not to be anything is the desire not to be.
1/29/2010 8:36:54 PM #
Hey this is really nice information. I was looking for something similar like this. Thanks for this useful information.
1/30/2010 4:37:24 PM #
The beauty of these blogging engines and CMS platforms is the lack of limitations and ease of manipulation that allows developers to implement rich content and 'skin' the site in such a way that with very little effort one would never notice what it is making the site tick all without limiting content and effectiveness.
2/1/2010 6:01:44 AM #
I personally have embraced the new technologies and the CMS platforms, I think the new tools only make the web designs better. I am glad that new technologies are coming out in web design that make things easier, improved, and better looking for design.
SEO
2/3/2010 7:36:33 AM #
Excellent post.I want to thank you for this informative read, I really appreciate sharing this great post. Keep up your work…
2/4/2010 2:14:52 AM #
Starting to understand a bit more now... Thanks for keeping it simple!
2/4/2010 2:57:42 AM #
Really appreciate this post. It’s hard to sort the good from the bad sometimes, but I think you’ve nailed it!
2/5/2010 3:17:27 AM #
I don’t know much about this. I am new in this field. You have done a great job.Thanks

2/5/2010 5:01:08 AM #
It is such an important topic and ignored by so many, even professionals. I thank you to help making people more aware of possible issues.
2/6/2010 12:15:55 AM #
Always worth visiting your blog to read your cool posts. Keep them coming.
2/6/2010 7:55:42 PM #
While surfing Yahoo I clicked on your link...very informative! I enjoy staying up-to-date about this kind of info.
I'll definitely bookmark your site for additional review.
2/7/2010 3:35:53 AM #
You have got some great posts in your blog. I will be visiting again.
2/7/2010 11:35:34 AM #
Thanks for good information.
2/7/2010 10:18:29 PM #
Thank nice post
2/8/2010 12:31:29 AM #
Dude.. I am not much into reading, but somehow I got to read lots of articles on your blog. Its amazing how interesting it is for me to visit you very often.
2/8/2010 5:11:46 PM #
I tried six times this afternoon to access your site. Are there problems with your site hosting? Or is it on my end?
2/8/2010 5:12:14 PM #
I tried six times this afternoon to access your site. Are there problems with your site hosting? Or is it on my end?
2/9/2010 12:27:46 AM #
Hey - nice blog, just looking around some blogs, seems a pretty nice platform you are using. I'm currently using Wordpress for a few of my sites but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it?
2/9/2010 10:21:07 AM #
Most people give up just when they're about to achieve success.
2/9/2010 4:54:46 PM #
Thanks for good information.
2/11/2010 6:36:30 AM #
Top post. I look forward to reading more. Cheers
Comments are closed