Windows Phone 7 Mango - BingMapsDirectionsTask Windows Phone 7 Mango - Sockets

Windows Phone 7 Mango - BingMapsTask

Published on Wednesday, May 25, 2011 7:30:00 AM UTC in Programming

Update 2011-09-30: This article is compatible with the final version of Windows Phone 7.1 "Mango".

The next version of Windows Phone 7 will introduce a set of new tasks that allow your applications to launch and use additional built-in features of the phone. One of these tasks is the BingMapsTask which some of you may remember (it was removed from the SDK in a CTP release a year ago). That task launches the Bing Maps application either at the user's current or an optional specific location. Additionally, you can provide a search term to tag matching locations on the map. Here is how the task is used.


The sample application consists of a simple UI like this:


It allows you to enter a search term (can be left leave empty to deactivate search), a location (uncheck "Use location" to deactivate) and the initial zoom level of the map. As soon as you hit "Go" the task is created and shown.

// create the task var task = new BingMapsTask()
                    SearchTerm = searchTerm,
                    Center = coordinate,
                    ZoomLevel = zoomLevel

// try to show the task // (may fail if searchTerm = coordinate = null) try {
catch (Exception ex)
    MessageBox.Show("Error while showing task: " + ex.Message);

This is really straight-forward code. As the try-catch-block and the comment indicates, you have to either set the search term or the coordinate to center the map at. If both are set to null or left empty, you'll receive an invalid operation exception.

What you need in addition is add a reference to the assembly System.Device. The related classes, like GeoCoordinate, are in the System.Device.Location namespace.


The sample values in the screenshot work really well and reliably show restaurants in New York.


However, I found that various combinations of the three parameters produce weird results. For example, as soon as you leave out the search term, the map control switches to a different mode, and suddenly the zoom level is interpreted differently: the same level of 3.0 like before now suddenly shows a large part of the world:

Zoom level 3.0, no search term

I wasn't able to find more information about the treatment of zoom level values; the only API restriction is that it has to be greater than zero.

Another issue is that as soon as you do not specify a center location, the map is supposed to center on the current user's location (according to the documentation). I found that this doesn't work at all in the emulator (where your current location is Redmond by default), and values you manipulate with the new location tools also are not picked up; instead, the last location is used. These problems are probably owed to the fact that the current tools/emulator and SDK are still in beta state.

A word on geo coordinates

At the moment there doesn't seem to be a way to get latitude and longitude values for a civic address through a phone API. There's a class in the System.Device.Location namespace that seems to be intended to do the opposite conversion (CivicAddressResolver), but it is still not implemented at the moment. To retrieve your current position, you can of course still use the GeoCoordinateWatcher class. However, if you need to get locations of other places, you have to rely on external services, like the Bing Geocode Service.

One thing to note is that only the latitude and longitude values of the GeoCoordinate class are used for the task. None of the other properties the class offers make any difference in that context.


With the new BingMapsTask, situations where you simply need to show a certain location on the map or want to do a location-based search become pretty easy and don't require using extra controls in your application. However, due to the lack of a built-in geocoding API, your possibilities are somewhat limited when you're not using external services for that. The following download contains the sample application shown in the screenshots above:

Download sample source code

Tags: Bing · Mango · Silverlight · Windows Phone 7