Introduction:
In this article we are going to see the most useful control on the Windows Phone 7 development, yes the BING Map Control. The BING Map Silverlight control for Windows Phone 7 development combines the power of Silverlight and Bing maps to get the best mapping experience for the developers and the real users to create location based application.
BING Map control in Windows Phone 7 application development are derived from the name spaces Microsoft.Phone.Controls and Microsoft.Phone.Controls.Maps. Developers need to register for the BING Map developers account to get the keys which are used in developing the application with the Bing Maps. Here in this article we will see the step by step process on how to make use of the BING Maps control and get the most enriching map application. [more]
Steps:
Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 application with a valid project name as shown in the screen below.
Note – To get the BING Map Keys first we need to register to the BING Map account using the below URL
http://www.bingmapsportal.com/
Once we register with our valid Windows Live ID we need to login again and go to the section Create or View Keys under the My Account category
Now we will be requested to provide the application details like below
- Application name: a valid application name
- Application URL: a valid application URL to access
- Application type: a valid application type to be selected from the list
Once we provided the details we will be provided with the BING Maps key as shown in the screen below.
Now we need to go back to the Visual Studio 2010 F5debugWp7BingMapControl project and start designing the application by dragging and dropping the BING Map control from the tool box and some buttons as shown in the screen below.
XAML Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now we need to use the below using directive to start using the map properties to the code behind. So add the below code first to the using list at the top
Code Behind:
|
|
Now we need to add below code to the Road View and Aerial View button click events as shown in the code below.
Code Behind:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now build and execute the application to check the first 2 button is working as expected. Press F5 to start building the project and we can see the application loaded to the Windows Phone 7 Emulator as shown in the screen below.
We can see a message Invalid Credentials: Sign up for a developer account at: http://www.microsoft.com/maps/developers as shown in the screen above. To remove this message we need to make use of the key which we got after registering with the Bing Maps website. So go to the XAML Code and add the key to the BING Maps section as shown in the screen below.
XAML Code:
|
|
Now run the application again by pressing the F5 key and we can see the error message is removed and the application in Aerial View and Road View as shown in the screens below.
Now we will write our code to do the zooming for the maps. Write the below code in the respective code behind to get the Zoom in and Zoom out as shown in the code below.
Code Behind:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now build and execute the project and we can see the Zoom in and Zoom out of the maps effectively as shown in the screens below.
Now we got the expected output as shown in the above screens, now let us do a add on task of pinning the location normally we need to do while travelling using a map direction. To start coding the PINNING option first add the map1_MouseLeftButtonUp event and write the below code which will do the location pinning as shown in the screen below.
Code Behind:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now we are done with our code, let us build and execute the application by pressing F5 and we can see the expected output. Just use the Mouse Up to click on the location shown in the Windows Phone 7 Emulator to pin the location as shown in the screens below.
Conclusion:
So in this article we have seen how to use the BING Map control effectively with the Windows Phone 7 development to build a rich user experience.
No Comments
Sir ,
Thanks for all your documents . i am new in this field. I like your all posts as they are my first resource to learn .
Right now i am using a bing map ui in Windows Phone 7. can you please help me here.
I want to use bing maps ui element for some actions to perform on it .
How can we display route with directions including way points address.
I some how managed to get route way points and their address.
But i need to know how to get directions along it.
Can you please refer a post or guide me in this .
Thank You
Sanjay Pachar