Friday 17 December 2010

'Verkeer' Windows Phone 7 application is now Live

After working on for over two months I can finally announce that my 'Verkeer' application is now globally available in the Windows Phone Market Place for free. And given Dutch traffic conditions today I'd say not a day to soon.


Summary of the 'Verkeer'application

The Verkeer application offers an up-to-date map based view of current traffic jams and speed camera's in the Netherlands. You can zoom and pan to specific locations of interest and store those as favorites for quick access. Additionally the application supports a Live-Tile allowing you to view current traffic conditions right in the home screen.


You can find the app in the WP7 Market place under the name 'Verkeer' or you can follow this Zune store link. Finally a few screen shots to give you an Idea of what the app looks like.





Saturday 4 December 2010

Creating an application installation and usage tracker for Windows Phone 7



As an application developer you are generally interested in knowing how many times your application has been installed and how often it's really being used. Unfortunately WP7 and its market place don't offer this capabilities (yet?) so I decided to leverage a good old fashion website tracker.
My first idea was to use Google analytics because it has excellent reporting capabilities but unfortunately analytics only works if you integrate it with something that that runs JavaScript. It works with the WP7 Browser control but that control only works if it is visible. So to use Google analytics I had to include (two) visible browser controls in my application and suffer their overhead.
Instead I turned to http://www.statcounter.com/. They are free and offer the ability for tracking through a downloadable image that you can set to be 1x1 Pixel. I configured two counters, 1 for first start up and one for repeated startup and use the following code to call them:
private
static
void LoadUrl(string url)
{
   ThreadStart tStart = new
   ThreadStart(() =>
   {
   try
     
         HttpWebRequest trafficInfoRequest = WebRequest.CreateHttp(url);

         IAsyncResult result = (IAsyncResult)trafficInfoRequest.BeginGetResponse(new
         AsyncCallback((asynchronousResult) =>
         {
         try
            {
               HttpWebResponse trafficInforResponse = (HttpWebResponse)trafficInfoRequest.EndGetResponse(asynchronousResult);
               StreamReader counter = new
               StreamReader(trafficInforResponse.GetResponseStream());

               counter.ReadToEnd();
            }
         catch { };
      }), null);
   }
   catch { }
   });

   Thread solo = new
   Thread(tStart);
   solo.Start();
}


Nice and asynchronous.
These are the stats so far

Wednesday 1 December 2010

Why does my Map Zoom property keep being reset to 1?


While working on my phone application I encountered an odd problem, after loading and setting my Map's ZoomLevel it promptly got set to 1 instead.
My setup was simple, in line with the MVVM pattern I had a MapControl's Zoom and Center properties databound to my View Model object. At the start of my application I loaded the View Models Zoom and Center values from a file on disk and this worked fine. But when my application resumed and I loaded these from the application state object instead they would be loaded and set correctly but immediately afterwards the Zoom would be overridden by the value 1.
Turns out the problem is caused by the order in which I set the two properties.
Apparently if you set the Center first and the Zoomlevel second the databinding circle sets the Zoom to a previous version (in my case 1). Do it the other way around and it works perfectly. Feels counterintuitive but it probably has to do with the fact that internally Zoom level and Center are converted into a Bounding box and that box is then databound back at the Zoom value of the control. So:
Wrong:
this.Center = (GeoCoordinate)PhoneApplicationService.Current.State["Center"];
this.ZoomLevel = (double)PhoneApplicationService.Current.State["ZoomLevel"];

Right:
this.ZoomLevel = (double)PhoneApplicationService.Current.State["ZoomLevel"];
this.Center = (GeoCoordinate)PhoneApplicationService.Current.State["Center"];

Thursday 4 November 2010

Windows Phone 7, How to use the Map control on a Pivot or Panorama


Place a Bing map control on a Pivot or Panorama in Windows Phone 7 and you'll notice that every time you try to manipulate the map with a swipe to left or right the Pivot/Panorma will move as well. In fact performing a swipe on the Map control as soon as the application starts without even ever touching the Pivot/Panorama results in a 'NullRefrenceException' with the following trace stack:
"at Microsoft.Phone.Gestures.GestureHelper.ReleaseMouseCaptureAtGestureOrigin()\r\n at Microsoft.Phone.Gestures.GestureHelper.NotifyMove(InputDeltaArgs args)\r\n at Microsoft.Phone.Gestures.ManipulationGestureHelper.Target_ManipulationDelta(Object sender, ManipulationDeltaEventArgs e)\r\n at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)\r\n at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)\r\n"
(Interestingly enough the Microsoft.Phone.Gestures namespace appears to be completely undocumented. It can be added in your using section but will be unresolvable until compilation.)

The problem however seems to stem from the fact that both controls are triggered by the same Gesture motion. Some therefore say that utilizing the Map control on a Pivot\ Panorama is either not a good idea or not even possible.
That apporoach however strikes me as incorrect because just by setting the Map controls IsHitTestVisible="False" the problem no longer occurs and you can use the map in read only mode.

But what if you really want to use the map control and just not have the Pivot/Panorama respond to gestures clearly aimed at the map?
Well instead of disabling the IsHitTestVisible property of the Map use the Maps MouseLeftButtonDown event to set the Panorama's to false
private
void MapOne_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

{

this.PanOne.IsHitTestVisible = false;

}

Just don't forget to use the ApplicationPage's MouseLeftButtonUp event to restore it otherwise the application will become nonresponsive.
private
void PhoneApplicationPage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

{

this.PanOne.IsHitTestVisible = true;

}
(use the application page one beceause the Maps MouseLeftButtonUp event doesn't fire if your swipe ended outside the control)
There is a drawback to this. At least in my emulator the map control seems a bit more unresponsive.
Could be an emulator thing, could be there is a better even to hook up to. I'll work on that to see if I can get a better solution.

-Leon

Monday 25 October 2010

A common XNA error


One of the XNA errors that regularly manages to confuse me is the exception:
Service provider object of type <Insert your object here> must be assignable to service type System.RuntimeType.
Since a quick Google search for the exception provided few results I figured I post the cause and solution.
In XNA there is the game.ServiceProvider object that provides a neat service based way of storing you game services without tying them directly to business logic. The predominant way of calling this method is:

this.Services.AddService(typeof(<Iinterface>), <Object>);
 

The exception occurs when your <Object> does not implement the provided <Iinterface> interface. Really simple and trivial to fix. Unfortunately forgetting to implement a particular interface seems to be something I regularly when I am developing a piece of functionality in small chunks of time. Just unfortunate that the error message is so unspecific.
Hope this helps
-Leon

Tuesday 19 October 2010

No Silver Bullet

I’ve been going through my old email and it seems that I am postponing setting up this blog since January 2007 as that’s the date Dr. Brooks gave me his blessing for the name of the site. I also think that I would probably have postponed it for quite a while to come if it hadn’t been for my foray into SP2010 and XNA for Windows Phone.

There are just to many things in there that need to be written down. Even if only to help me find them again myself.

Given the title of the site I would like to end this first post with a fitting reference. Software engineers will recognize the title of this website as a reference to Fred Brooks's 1986 paper, "No Silver Bullet", now reprinted as Chapter 16 in his The Mythical Man-Month, Anniversary Edition (1995).  Although my ideas are influenced by his writings, this website has no connection with Dr. Brooks. (although I did asked and received his  approval to name the site the way I did)
-Leon