Click here to Skip to main content
15,885,810 members
Articles / .NET / .NET4

Bing Maps in Silverlight 4

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
26 Jun 2010CPOL3 min read 34.6K   10   2
How to get started with bing maps in your Silverlight app

Introduction

This article is meant to help everyone that wants to get started using Bing Maps in Silverlight. For this, we'll create a simple "Where are We" page in a sample project.

Downloading and Installing the Control

Google "download Silverlight bing maps" and you should get the link to the latest release. It is just a .msi file, so let's install it.

Now it is installed, there's a new folder under C:\Program Files\ called Bing Maps Silverlight Control. There, we can find the documentation and the libraries.

Using the Code

Once in Visual Studio, and with our solution opened, go to Project-> Add Reference -> Browse tab, and find the Bing Maps Silverlight Control folder under C:\Program Files, and add the reference, as shown in the image below:

AddReference.png

Now, in our WhereAreWe.xaml page, let's add the XML namespace:

AddNameSpace.png

Now, we can use the control in our page:

MapXaml.png

Let's see the map properties for just a minute (avoiding the layout ones):

  • Credentials provider: For now (I'm using the control's Beta's v1), we have to register our application to get a credential that allows us to use the map control. We can register up to 5 apps. The registration code we get is the one we set in the CredentialsProvider property (see this link for more information.)
  • Center: Center point that we want our map to display when loaded
  • CopyrightVisibility: To show/hide the map control's copyright
  • Culture: The language/culture that we want to use in our map control
  • LogoVisibility: To show/hide Bing Maps' logo
  • ZoomLevel: The map zoom's distance (1 being the furthest)

How Do We Get an Address Point?

We need to know that to set the Center point and our locations. Let's go to Bing Maps, and look up for a place, let's say Seville. Once we get the result and the city is being shown in the map, we'll write javascript:map.GetCenter() in the browser's address bar. We'll get something like this: (37.38763567060232, -6.001807451248169).

So. our center point would be-> Center="37.38763567060232,-6.001807451248469". Please notice that there's no space between both values when we set the point, just a "," symbol.

Placing our Locations in the Map

MapChildren.png

We can create a Children section for our map. In this case, I'm using a canvas for each child. Take a look at the m:MapLayer.Position property. That's the point where we want our children to appear in the map. I'm just using an image to let the user know where our places are, but we could take advantage of the XAML's power and flexibility and use rotations, effects, triggers... whatever we want.

We can add as many children as needed. Of course, we could do this dynamically in the code behind, which I think would be the best way to do it if we have to display a large variable number of locations.

If you run the application, you will notice that the control runs fast, and you will like the transition effects when a zoom level or a location is changed.

Thanks for your time reading this article. Please fell free to post any comment/suggestion/doubt that you have. Maybe another day, we'll discuss how to let the user write an address and show back the location in the map.

Hope it helps!

(See this link for more information.)

History

  • 26th June, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Spain Spain
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSuggestion Pin
BryanWilkins28-Jun-10 6:46
professionalBryanWilkins28-Jun-10 6:46 
GeneralRe: Suggestion Pin
nereo.lopez28-Jun-10 7:32
nereo.lopez28-Jun-10 7:32 
Hi Bryan,

thanks for your suggestion. I'm finishing my project and should be published this week. I'll update the article with a link to the web page, so everybody that wants to see a live sample can do it.

Thanks again!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.