Blog Archives

Generic Bing maps pushpin clustering component for Windows Phone 7

A couple of weeks ago I wrote my own Windows Phone app Lovely Neighbourhood which is showing pushpins on the Bing maps control for Windows Phone 7. Because there where quit some pushpins close to each other I decided to use pushpin clustering (sometimes called marker clustering) to make map in the app look less chaotic than with all the pushpins on the map. (There where a few regions where you couldn’t even see the map anymore.)

After a little search I found a blog post by Colin Eberhardt who has a guide to pushpin clustering in WP7. I started implementing and after a few changes it works fine in my app. But than I saw an app from my colleague which was not using pushpin clustering and also on his map view it was pretty hard to see the map. At that moment I started thinking about rewriting the pushpin clustering code in a generic way, so it would be easy to implement in any app.

In this article I want to show you how to use my pushpin clustering component in your app.

The first step that you need to do is add a reference to the PushPinClusterer.dllin your project.

The next step will be to add the IClusteredGeoObject interface to your entity which has the GeoCoordinate property.

1 public class MyGeoObject : IClusteredGeoObject 2 { 3 public string Name { get; set; } 4 public string Country { get; set; } 5 6 public GeoCoordinate Coordinate { get; set; } 7 8 }

When you implement the interface, you have to implement the Coordinate property which is of type GeoCoordinate. You can just use this property as your location property, or in the getter/setter return/set your own GeoCoordinate property. After implementing the IClusteredGeoObject your entity is ready to be clustered.

The next step will be to setup your xaml so you have a layer where you can add the pushpins and a DataTemplate so you can make a difference between the objects you want to show on the map in case of a clustered pushpin or a normal pushpin.

Below you find the XAML for my Bing maps control with the MapItemsControl where I bind the ObservableCollection<T> from my pushpin clusterer and we reference the “pushpinSelector” datatemplate.

1 <my:Map Height="601" Name="map1" Width="456"> 2 <my:MapItemsControl Name="pushPinModelsLayer" 3 ItemsSource="{Binding PushpinModels}" 4 ItemTemplate="{StaticResource pushpinSelector}" /> 5 </my:Map>

The next step is adding the datatemplate to our resources section like below:

1 <DataTemplate x:Key="pushpinSelector"> 2 <my:Pushpin Location="{Binding Location}" CacheMode="BitmapCache"> 3 <my:Pushpin.Template> 4 <ControlTemplate> 5 <clusterer:PushpinTemplateSelector Content="{Binding}"> 6 <clusterer:PushpinTemplateSelector.ClusterTemplate> 7 <DataTemplate> 8 <Grid VerticalAlignment="Center" HorizontalAlignment="Center"> 9 <Ellipse Fill="Red" Width="40" Height="40" /> 10 <TextBlock Foreground="White" Text="{Binding ClusterCount}" 11 HorizontalAlignment="Center" VerticalAlignment="Center" /> 12 </Grid> 13 </DataTemplate> 14 </clusterer:PushpinTemplateSelector.ClusterTemplate> 15 <clusterer:PushpinTemplateSelector.PushpinTemplate> 16 <DataTemplate> 17 <StackPanel Background="Black"> 18 <TextBlock Text="{Binding CurrentObject.Name}" Foreground="White" /> 19 </StackPanel> 20 </DataTemplate> 21 </clusterer:PushpinTemplateSelector.PushpinTemplate> 22 </clusterer:PushpinTemplateSelector> 23 </ControlTemplate> 24 </my:Pushpin.Template> 25 </my:Pushpin> 26 </DataTemplate>

As you can see in the above xaml markup we have two pushpin templates, one for the clustered pushpins and one for the normal pushpins. The pushpin clusterer is telling you how many pushpins there are clustered by binding the Count property. In the “normal” pushpin you will get your object back from the binding by calling the CurrentObject property. So if you have a property Name on your entity you can bind it here by calling CurrentObject.Name.

The only thing we now have to do is load our data, for example in the OnNavigatedTo event where you can load the list of entities which have IClusteredGeoObject implemented. The following code can be used to start clustering your pushpins.

1 var clusterer = new PushpinClusterer<MyGeoObject>(map1, pins, 50); 2 pushPinModelsLayer.DataContext = clusterer;

When instantiating the PushPinClusterer you give the Type of your entity to the clusterer and as parameters the map you have defined in your xaml, the list of entities and an integer with the distance in pixels in which pushpins have to be clustered.

If you need to know when the clustering is complete you can subscribe to the ClusteringCompleted event, which will fire when it is finished clustering the pushpins.

That’s it, if you start your app now it will start clustering your pushpins.

I have created an example solution with the steps as described above, which you can download from my blog.

Hope this will help you adding pushpin clustering to your app, and I love to hear it from you if used it and in which app. If you have any questions, suggestions or anything else you can contact me on twitter by using @bloodyairtimer or leave a comment on this post.

Happy coding!

“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:

Updated language support in Windows Phone 7 “Mango”

In the first release of Windows Phone 7 there was support for a few languages (English (US and UK), French, German, Italian, and Spanish.) With the Mango update Microsoft is adding 17 more languages: Brazilian Portuguese, Chinese (simplified and traditional), Czech, Danish, Dutch, Finnish, Greek, Hungarian, Japanese, Korean, Norwegian (Bokmål), Polish, Portuguese, Russian, and Swedish.

 

As I blogged earlier about the Windows Phone 7 directions button missing and how to get your directions button back. This feature is with Mango updated with support in 19 countries. As you can see in below list of features and in which language it is supported, the “Local search results” or “Scout”  as it is called either, will only be available (for now) in the Windows Phone 7 “Launch” countries. Note that if you set your browser & search language to a non supported language than the “Scout” button will disappear from the Bing Maps menu bar.

 

ScoutButton <= That’s the one you’re missing if you are setting the Browser & Search language to a non Local search results country.

 

  • Bing search (accessed from the phone’s hardware Search button) is available in 33 countries: Argentina, Australia, Austria, Belgium, Brazil, Canada, Denmark, Finland, France, Germany, Hong Kong, India, Indonesia, Ireland, Italy, Japan, Korea, Malaysia, Mexico, Netherlands, New Zealand, Norway, Philippines, Portugal, Russia, Singapore, South Africa, Spain, Sweden, Switzerland, Taiwan, United Kingdom, and the United States. (Elsewhere, handset and mobile operators can configure the hardware search button to a locally-relevant search site).
  • Local search results show up in 6 countries: Australia, Canada, France, Germany, United Kingdom, and the United States.
  • Maps is supported in 19 countries: Australia, Austria, Belgium, Brazil, Canada, Denmark, Finland, France, Germany, Italy, Netherlands, New Zealand, Portugal, Singapore, Spain, Sweden, Switzerland, United Kingdom, and the United States.
  • Voice-to-text and Voice-to-dial is available in 6 countries: France, Germany, Italy, Spain, United Kingdom, and the Unites States.
  • Voice search is supported in 4 countries: France, Germany, United Kingdom, and the United States.

 

One nice thing to mention about the language and region settings is that there are a lot of settings which in Mango don’t require your device to be restarted, but can be applied instant. That makes it easier to play around with these settings and find your own favorite.

 

Language support source:

http://www.everythingwm.com/microsoft-details-language-support-in-mango-update-for-windows-phone/2011/07/11/#more-4824

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.

First impression on the HTC Trophy with Windows Phone 7

Today I received my HTC Trophy with Windows Phone 7 from my employer Avanade Netherlands. In this small post i will cover my first impression about this phone and the new mobile OS.

First of all: I’am not a very experienced smartphone user, have only used smartphones with Windows Mobile OS. So I will compare this phone against the experience I have with the previous versions.

After unboxing the phone, and installing the SIM card into it, I turned on the phone and it started a very clean and simple wizard which updated some settings like the region etc. Within five minutes I was able to read my email, surf the web and download apps from the marketplace. Easy as what!

Capacitive screen

When working through the wizard I already noted that the capacitive screen is working very smooth. It responds directly to finger gestures and moves in a nice speed.  This works really nice compared to the ‘old’ HTC Touch pro I was used to.

Tiles

The tiles on the home screen look very nice and clear to me. Customization is very easy, so it your phone will become soon your personal device. HTC has decided to no change very much to the home screen. They’ve added an HTC hub which is mostly doing something with the wheater and looks like the ‘old’ WM 6.5 screen. Not really interesting in my oponion. At least I expected more of it.

Clean fonts

When reading websites on the internet and working with some apps, I noticed that there are very clean fonts used in WP7. Reading from the screen is like an angel is touching your eyes :) . I’am getting a little bit to enthousiastic.

Onscreen keyboard

The onscreen keyboard is working very quick through it’s autocomplete functionality that even includes some dutch words. (Not all) I have choosen my previous phone with a hardware keyboard because I was not expecting that the onscreen keyboard will be handy enough. With this phone I was also worried a bit about this issue, but for now this onscreen keyboard works like a charm.

Bad things

Most people will ask: Haven’t you noticed anything bad in your first impression? Well, I don’t want to call it bad things but I think there are things missing. For example there is not very much information about your device status. (At least i haven’t found it) battery and memory status. Also the settings which you can change are minimal. It means you are not able to screw up the phone, but I like to change settings.

Overall I have a good feeling about the first impression and think that Ms has done a great job when building this OS. This definitly can be an Iphone killer if they have added the copy/paste functionality and tethering support.

Later on I will come up with pictures and probably a movie.