How to Search the Telerik Map Control in Silverlight4

Posted by in Silverlight category on for Beginner level | Points: 250 | Views : 8900 red flag

This is the coolest thing I have ever done with the Telerik’s Silverlight map Control. The Control it’s so easy to use. The Previous article I have written on the Map control of was based on co-ordinates, it is good when you want to display certain areas, but if you want people to search certain location, you will need to allow them to enter the location of the place. I had a look at one of the demos presented by Telerik and to my surprise it was very easy to do. I even search my home town.


This is the coolest thing I have ever done with the Telerik’s Silverlight map Control. The Control it’s so easy to use.  The Previous article I have written on the Map control of was based on co-ordinates, it is good when you want to display certain areas, but if you want people to search certain location, you will need to allow them to enter the location of the place. I had a look at one of the demos presented by Telerik and to my surprise it was very easy to do. I even search my home town.


In this Article, I am going to show you how to create a Silverlight GIS application that will allow your user to search a certain location. The users will enter the name of the place and the map will focus on the place in an Aerial map view.

Using the code

We are going to use C# as our main Language for example code  

Tools you need

I have made a table of tools you need to follow this example.

Obviously you need to have Silverlight installed on your machine, and you need visual studio 2010, because this version of Map Controls is for .net 4.

1)    First if you are not registered at Telerik, register here

2)    You need to create an Account with Bing, if you have a Windows Live account , you will automatically log in, you will not need to create a new one. So you will use this and after you have logged in , you must create a key, this key is the one we will use in the map. You will be asked for a website, just add anything, and a strange key will be created , hold on to it, we will use it later in the code.

Tools you need

Name of Tool

Version of .Net

Where to get it

RadControls for Silverlight


.NET 4

.NET Developer runtime

.NET 4



First, if you have Visual Studio opened, close it and run the setup of the Telerik Silverlight Controls, please notes that, this will not only install the map control, but it will install other controls also, that we might need in the future articles on the cool stuff using Telerik controls. When done, we can start up your visual studio, and you will not need to add them manual as we used to do in the previous versions of the controls.


Silverlight controls , not only Telerik, will need you to add namespaces before you use them , if this is your first Silverlight example, the namespaces are a bit different from the one , you have been using in, or C# or other .NET Languages. So to make things simple for yourself. Go to your toolbar and hopefully, it will look like this

Choose the Map control, drag it and drop it on your Silverlight page, and you will notice, that namespaces are added automatically and the references are added also. So this means you don’t need to update your Xaml on the namespaces. That is why I hate to use some third party controls, because some examples on their site or some controls don’t add namespaces automatically for you, you have to spend a lot of thing hacking the controls so that the compiler don’t complain. Now let’s make it more interesting as Telerik Demo does, this is very simple. Go to your Xaml (MainPage.xaml) and make sure it looks like this; you can decide to copy and paste.

<UserControl x:Class="MapSearch.MainPage"






d:DesignHeight="486" d:DesignWidth="780" xmlns:telerik="">

<Grid x:Name="LayoutRoot" Background="White" Height="486" Width="780">

<telerik:RadMap x:Name="RadMap1" ZoomLevel="7" Center="42.358431, -71.059773" Margin="0,61,12,12">

<telerik:InformationLayer Name="informationLayer">



<Border Background="#7FFFFFFF"




<ToolTip Content="{Binding Path=Title}" />



<telerik:HotSpot X="0.5" Y="0.5" />




<ColumnDefinition Width="14" />

<ColumnDefinition Width="Auto" />


<Path Fill="Red">



<EllipseGeometry Center="7,7" RadiusX="3" RadiusY="3" />

<EllipseGeometry Center="7,7" RadiusX="7" RadiusY="7" />









<telerik:InformationLayer Name="informationLayer2" />


<TextBox Height="23" HorizontalAlignment="Right" Margin="0,14,327,0" Name="SearchCondition" VerticalAlignment="Top" Width="266" />

<TextBlock Height="19" HorizontalAlignment="Left" Margin="19,18,0,0" Name="lblSearch" Text="Enter your Search LocationL:" VerticalAlignment="Top" Width="152" />

<telerik:RadButton Content="Search" Height="22" HorizontalAlignment="Left" Margin="480,15,0,0" Name="btnSearch" VerticalAlignment="Top" Width="104" Click="btnSearch_Click" />



Ok above here, I have my map control and I have one textbox. I have not used any co-ordinates , so if  you search with any place , the map will refresh and it will show you a new location. I have searched for my home town Mamelodi (Pretoria) in South Africa.

And the Server side will look like this

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Browser;

using System.Windows.Data;

using Telerik.Windows.Controls;

using Telerik.Windows.Controls.Map;

using ItemsControl = Telerik.Windows.Controls.ItemsControl;

using Telerik.Windows.Examples.Map.Search;


namespace MapSearch


public partial class MainPage : UserControl


private string VEKey;

private MapItemsCollection itemCollection = new MapItemsCollection();

private BingSearchProvider searchProvider;

public MainPage()




this.informationLayer.DataMappings.Add(new DataMapping("Location", DataMember.Location));

Binding binding = new Binding();

binding.Source = this.itemCollection;

this.informationLayer.SetBinding(ItemsControl.ItemsSourceProperty, binding);



// Initialize Virtual Earth map provider.

private void SetProvider()


BingMapProvider provider = new BingMapProvider(MapMode.Aerial, true, this.VEKey);

this.RadMap1.Provider = provider;

// Init searh provider.

searchProvider = new BingSearchProvider()


ApplicationId = this.VEKey,

MapControl = this.RadMap1


searchProvider.SearchCompleted += new EventHandler<SearchCompletedEventArgs>(Provider_SearchCompleted);



private void GetVEServiceKey()


WebClient wc = new WebClient();

wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);

Uri keyURI = new Uri(HtmlPage.Document.DocumentUri, "AlTTXGRrAlAD_ANxWHkwshIVLoBLCryJjB5adacuGgcQSzd9UQZaow8hVLPIUNMV");




void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)


this.VEKey = "AlTTXGRrAlAD_TestVLoBLCryJjB5adacuGTest9UQZTestUNMV";//e.Result;




private void SearchHandler(object sender, RoutedEventArgs e)




private void Provider_SearchCompleted(object sender, SearchCompletedEventArgs args)


SearchResponse response = args.Response;

if (response.ResultSets[0].Results.Count > 0)



foreach (SearchResultBase result in response.ResultSets[0].Results)


MyMapItem item = new MyMapItem()


Title = result.Name,

Location = result.LocationData.Locations[0]





if (response.ResultSets[0].SearchRegion != null)


// Set map viewport to the best view returned in the search result.


// Show map shape around bounding area

if (response.ResultSets[0].SearchRegion.BoundingArea != null)


MapShape boundingArea = response.ResultSets[0].SearchRegion.BoundingArea;

boundingArea.Stroke = new SolidColorBrush(Colors.Red);

boundingArea.StrokeThickness = 1;



if (response.ResultSets[0].SearchRegion.GeocodeLocation.Address != null

&& response.ResultSets[0].SearchRegion.GeocodeLocation.Locations.Count > 0)


foreach (Location location in response.ResultSets[0].SearchRegion.GeocodeLocation.Locations)


MyMapItem item = new MyMapItem()


Title = response.ResultSets[0].SearchRegion.GeocodeLocation.Address.FormattedAddress,

Location = location








private void btnSearch_Click(object sender, RoutedEventArgs e)


string query = this.SearchCondition.Text;

if (!string.IsNullOrEmpty(query))


SearchRequest request = new SearchRequest()


Culture = new System.Globalization.CultureInfo("en-ZA"),

Query = query







Ok I know it’s too much for a start. But don’t worry too much about these functions. What they do, they help you to zoom in and out of the Map. When the Listbox is selected a selected place will make the map to zoom to that location. You can use your own location; you use Google maps to get your co-ordinates. Now there is an important part of the map that I want to explain.

private string VEKey = "AlTtestetest_ANxWHtestetestCryJjB5adactestetestUNMV";

When we started, I said keep the key that you have generated in the Bing site. Now I have messed up mine so that no one can you use it. Now just replace this string with your and when done build your application as you normally do and run your application and you will see this 


As you can see it came to my home town in a nice view.


Thank you for visiting Dotnetfunda

Vuyiswa Maseko

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Vuyiswa Maseko
Member Level: NotApplicable
Member Status: Member,MVP,Administrator
Member Since: 7/6/2008 11:50:44 PM
Country: South Africa
Thank you for posting at Dotnetfunda [Administrator]
Vuyiswa Junius Maseko is a Founder of Vimalsoft (Pty) Ltd ( and a forum moderator at www.DotnetFunda. Vuyiswa has been developing for 16 years now. his major strength are C# 1.1,2.0,3.0,3.5,4.0,4.5 and and sql and his interest were in, c#, Silverlight,wpf,wcf, wwf and now his interests are in Kinect for Windows,Unity 3D. He has been using .net since the beta version of it. Vuyiswa believes that Kinect and Hololen is the next generation of computing.Thanks to people like Chris Maunder (codeproject), Colin Angus Mackay (codeproject), Dave Kreskowiak (Codeproject), Sheo Narayan (.Netfunda),Rajesh Kumar(Microsoft) They have made vuyiswa what he is today.

Login to vote for this post.

Comments or Responses

Posted by: Madhu.b.rokkam on: 2/18/2011 | Points: 25
Very nice article..Thanks
Posted by: Tripati_tutu on: 2/19/2011 | Points: 25
Really this is helpful for us..........
Posted by: Samarmir on: 2/19/2011 | Points: 25
Thanks for this nice article.
Is it possible to do this with a aspx webform page?
Posted by: Vuyiswamb on: 2/19/2011 | Points: 25
yes , there is a map Control for in telerik.
Posted by: Vuyiswamb on: 2/19/2011 | Points: 25
Thank you :)

Login to post response

Comment using Facebook(Author doesn't get notification)