EziData Solutions

Web, NET and SQL Server

WP7 Mango Features #1: BingMapsTask

Now that the Tech-Ed finals for Spotlight2011 are over, I have had the chance to install the Mango pre-release image on my Windows Phone. I had only seen a few of the great new features in videos and a session at Tech-Ed, so it was good to actually get my hands on the real OS. Along with some very cool features from the users perspective, Mango has a host of new and improved features for developers. One that immediately jumped out was the new BingMapsTasks. 

If you have ever had to create a WP7 app that uses the Bing Maps API you’ll appreciate that it is not an easy task.  In fact, as great as the Windows Phone 7 Developer Labs were, I always struggled with the Bing Maps labs. This was partly due to the fact that the labs chose to use a MVVM pattern, which was completely foreign to me at the time and added a level of complexity that made learning how to use the API overly difficult.

You will be happy to know that the WP7 Mango release has come to your rescue with some new ‘launchers’ specifically designed to leverage the Bing Maps application built into the OS. Similar to the email and camera launchers currently available to Windows Phone developers the BingMapsDirectionsTask and BingMapsTask can be used to directly launch the Bing Maps application.

Start a new project and be sure to target the 7.1 Windows Phone OS.

The BingMapsTask is contained in the Microsoft.Phone.Tasks namespace, so you will need to add a using statement to your MainPage.xaml.cs file.

The first task we will look at is the Bing Search, which can be used to find businesses and landmarks located near a particular geographical point. By default, the current location of the device is used for the center of the search however you can specify any geographical location.

If you are using the emulator then you will want to declare a defined center for your search. To do this, add a reference to the System.Device library by right mouse clicking on the References folder in you project and selecting Add Reference. Once you have added the System.Device library you can add the following using statement to your MainPage.xaml.cs file;

Now you can define the Center for your search be creating a new GeoCoordinate object and setting its Latitude and Longitude to suitable values.


private void Button_Click(object sender, RoutedEventArgs e)
    BingMapsTask bmt = new BingMapsTask();
    bmt.Center = new GeoCoordinate(-27.5, 153);
    bmt.SearchTerm = ("coffee");


The code results in the Bing Maps app opening, centered at the specified location and showing all matching locations, in this case places related to coffee. The user can then use all the built-in Bing goodness, to browse around the matching businesses and get directions from their current location. All you had to do was write a few lines of code - very nice.

Posted: Aug 31 2011, 04:40 by CameronM | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: WP7