Sunday, February 6, 2011

Silverlight On Mobile : Using Bing Maps in your Windows Phone 7 Application

Few months back, I wrote one article on Integrating Bing Maps in Silverlight Application. Today on the same base I am putting my thoughts for Bing Maps on Windows Phone 7 in a very short demo. The way you integrate your Bing Maps in Silverlight Application and over here is almost same since platform for both is Silverlight. You need Key for Bing Maps and API in place so as to make things easy for you, You can refer my old article here.

For Windows Phone 7, Make sure you add reference to Microsoft.Phone.Controls.Maps like this :


Then next step is to add Id in App.xaml file (Refer my old post,you will come to know where to get that Big long Id from) like this :

Bing5You need to add reference for the same in your MainPage.xaml file like this :


Then just add BingMaps to content panel and you are ready !


It will look like this on your emulator :


If you want to provide more options like Zooming In and out you can put the same in App Bar like this :


You can use ZoomLevel property which is of type double to play with Zooming capabilities.You can also add pushpin to put specific location on map using PushPin class like this :

pushpin.Content = "My Home";
pushpin.FontSize = 30;

Well, for setting exact location you need to take help of Location class.Both Location and PushPin you need Microsoft.Phone.Controls.Maps namespace which we have added as reference to our project.You can put Lat-Lon like this :

local.Latitude = 18.31;
local.Longitude = 73.55;

You can then see output like this :


This is how you can integrate Bing Maps to your Windows Phone 7 application. I know this is very basic but this is first step for advance Map related apps,We will soon further discuss more aspects like Location based Apps and Services,GPS etc. I hope this small tutorial will help you to add Maps in your current ongoing Windows Phone 7 apps if there is a requirement of the same.Stay tuned ! more useful short and long articles coming on Windows Phone 7 and Silverlight together.


No comments: