Blog Archives

“Integrate" Bing Maps directions in your WP7 app

in the upcoming “Mango” update for Windows Phone 7, Microsoft has already released the Windows Phone Developer Tools Beta 2 for this new version which has got version number 7.1.

One of the new cool features which is included in this beta release is the support to use the “Directions” feature in Bing Maps from your app. This feature makes it very easy to make a location aware app and makes it interactive to the user to help him find a specific spot. (Think about an app that helps users find only your restaurants, ATM’s, your company or anything else that has a coordinate)

Please note that I’m trying to keep away from the “integrate” part, cause actually it’s not integrating but more like navigating away from your app to Bing Maps with the location you specified in your app.

Okay, bring on this new feature and show us how to do this.

First, let’s start with the introduction of this feature/class/task or how you want to call it. We are talking about the BingMapsDirectionsTask which is a very simple class that lives in the Microsoft.Phone.Tasks namespace. You can use this task to create a route on Bing Maps from your app. In short terms this class has three important objects (2 properties / 1 method). It has a Start and an End property, and a method Show() which is it.

Both properties are of type LabeledMapLocation, which have a constructor that expected a string for the name and GeoCoordinate for the location.

In general below code will be enough to create a route on the Bing Maps app:

1 BingMapsDirectionsTask directionTask = new BingMapsDirectionsTask(); 2 directionTask.Start = new LabeledMapLocation("Start", new GeoCoordinate(52.512794, 6.091539)); 3 directionTask.End = new LabeledMapLocation("End", new GeoCoordinate(52.512794, 6.091539)); 4 5 directionTask.Show();

Just three lines of code. Can it be easier?

Yes it can!

If you don’t assign a value to the start property than it will automatically take your location and calculate a route to your End location.

I have created a sample solution where you can use the locations from the emulator to specify a start location and when you click on the map it will take your position (which is set by the emulator) and calculate a route to the location you have clicked.

BingMapsLocationChooser

Choose a location by using the Additional tools.

BingMapsDirections

And there it is our own created direction in the Bing Maps app.

To be honest I’m a bit in doubt about what I think about this feature. On one side it’s a very handy, easily to implement feature that will give you navigation/routing to your location in minutes.

Another thought I still have is I’m adding a map control to my app, a user clicks around and if it needs to calculate a route it exits my app, and starts Bing Maps. No real integration.

Anyone having some thoughts about it?

Download:

Windows phone 7 directions button missing

When playing around in Windows Phone 7 I noticed that the Bing Maps functionality has a very nice and fast way to calculate a route from the point where you are by pressing the Directions button. (Your current location is determined by the A-GPS sensor in your WP7 device.) When calculating the route you have the choice to calculate a route driven by a car, or for walking.  Also finding a location on the map works easy by pressing the Find button and type a location or just speak to your phone to find it :) . When selecting details of the calculated route it smoothly zooms to the selected location. Very nice done.

“Current location on Bing Maps”

Normally I don’t use navigation a lot, but on my last vacation I was kind of lost the way back to my vacation home. I thought no problem at all, get my WP7 phone, start Bing Maps and voila find the route back home. WRONG…… Bing Maps was starting up and my current location was found within seconds, but there was no way to calculate a route or find a location on the map. The directions button was just disappeared. And when I tried to find a location, it only searches the internet and not the map. After a few tries Idecided to pickup my hardcopy map and navigate my way back on the ‘old school’ way. At that moment I was thinking that I did something wrong or that the internet connection wasn’t stable enough to calculate the route.

“Details of the calculated route on Bing Maps”

Back home I gave it another few tries, but without luck. Than I start thinking what settings do I have changed since I got my device. After a while I found out that I have changed the region settings from English to Netherlands. I have reverted this change, restarted my device and yes…….my directions button is back again.

I took the following steps to get my Directions and Find  functionality back on the Bing Maps:

1. Go to Settings

2. Open Region & Language

3. Change Browser & search language to English (United States)

4. Click on the link on top of the screen to accept the changes and restart your device.

I think that this functionality is only available in the languages in which WP7 is official launched. I will update this settings back to Netherlands when WP7 is officially launched in the Netherlands.