How to use Bing Maps In Windows 7 Phone

Download Sample Project (41.34 kb)

using bing maps in Windows 7 phone

Some of the cool applications on smart phones are developed to help present information to the user based on their geo locations. And lot of time it involves using maps. Since Windows 7 Phone development platform is based on Silverlight, use of Bing Maps Silverlight Control comes as a natural choice. But so far there is not a official release of the control specific to Windows 7 Phone. Good news is that since Windows 7 Phone SDK is built on top of Silverlight 3 platform, you can use current release of Bing Maps Control for Silverlight with a small caveat. In this post I will discuss how to use Bing Maps in Windows 7 Phone.

First thing first. You will need to make sure that you all the tools needed for Bing Maps development. I have explained this in my earlier post Using Bing Maps In Silverlight 4. The steps to use Bing Maps Silverlight Control are exactly the same as in your conventional Silverlight application development.

How to use Bing Maps in Windows 7 Phone

  • Create Windows 7 Phone project in Visual Studio 2010
  • Add reference to following assemblies in your project from location where you installed Bing Maps SDK.
    • Microsoft.Maps.MapControl
    • Microsoft.Maps.MapControl.Common

    Now compile the project to make sure that the reference to Bing Maps are correctly included. This is where you will hit the first road block. You will get a compile time error.

    error CS0234: The type or namespace name 'Maps' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    The primary reference "Microsoft.Maps.MapControl" could not be resolved because it has an indirect dependency on the framework assembly "System.Windows.Browser, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" which could not be resolved in the currently targeted framework. "Silverlight,Version=v4.0,Profile=WindowsPhone". To resolve this problem, either remove the reference "Microsoft.Maps.MapControl" or retarget your application to a framework version which contains "System.Windows.Browser, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e".

    Here is little piece of information you will need to know and is very important. As per Silverlight documentation for Windows 7 Phone namespace System.Windows.Browser is not supported on the device. Good news is that you can add reference to this assembly from the folder where your Silverlight assemblies are installed by Visual Studio. For example in my case the location is C:\Program Files\Microsoft Silverlight\4.0.50524.0\System.Windows.Browser.dll. Adding reference to this assembly does not mean that you can actually use all the APIs from this namespace. If you will try, you will get run time errors. Remember that this namespace is not supported in Windows 7 Phone platform. Now compile the project again and you should be good to go.

  • Now implement the code that will fetch data that needs to be used to render locations on Bing Maps. In previous post How to use WCF in Windows 7 Phone, I described use of WCF. In the sample project attached with the post, I am using WCF service to get geo locations that I want to plot on Bing Maps on Windows 7 Phone.

As I mentioned in previous posts about Windows 7 Phone development, you can cut and paste code from your regular Silverlight application in Windows 7 Phone application and it will work as long as you are not using any APIs that is not supported on Windows 7 Phone.

comments powered by Disqus

Search

Social

Weather

4.3 °C / 39.8 °F

weather conditions Clear

Monthly Posts

Blog Tags