HTC Touch Pro GPS Failing with Google Maps

HTC Touch Pro GPS Failing with Google Maps

Yesterday I did a hard reset of my HTC Touch Pro; actually I applied a clean ROM image but that’s a different story. For those who have spoken to me recently you will have heard how much I dislike my this device.  The actual device is great but it suffers from stability issues, coupled with negative levels of support from both HTC and Expansys (whom I purchased the device through).  I’ve also never been able to get the GPS to work via Google Maps.  You would have thought that since Google Maps is installed by default that they would have it configured to work with the GPS on the device.

Turns out that all you need to do is to change the GPS settings within Google Maps and hey presto it works:

Menu –> Options –> GPS Settings…

My Location Settings –> Set Manually [COM4 , 4800]

Of course this needs to match up with the GPS Settings on your device:

Start –> Settings –> System –> External GPS

Programs –> GPS Program Port [COM4]

Lastly, you should run QuickGPS (Start –> Programs –> QuickGPS –> Download) as this will significantly reduce the time it takes the GPS to locate satellites.

Building a Windows Forms Control using the Virtual Earth Web Services

Building a Windows Forms Control using the Virtual Earth Web Services

The process of building a Windows Forms Control is relatively simple – you are really just adjusting the way the control renders on the screen.  This typically means overriding the default paint behaviour to render the map image you want to display.  For a summary of how you can download a map image using the Virtual Earth Web Service you may want to check out this post.

Start by overriding both the OnPaint and OnBackgroundPant

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
}

protected override void OnPaintBackground(PaintEventArgs e)
{
    // Do nothing – this is important to reduce flicker
}

Now you need to actually do the painting within the OnPaint method. This is done by calling the DrawImage method that exists on the Graphics object from the PaintEventArgs.

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
   
    e.Graphics.DrawImage(this.controlImage, new Point(0,0));
}

The controlImage that is being displayed here is the map image that is downloaded via the DownloadImageFromUri method (see this post). This image needs to be updated whenever the Centre of the map or the Zoom changes.  For example on the control you may have properties that invoke a method to do the download:

public Location CentreOfMap
        {
            get
            {
                return centreOfMap;
            }
            set
            {
                if(centreOfMap == null || 
                  !centreOfMap.Equals(value) && value!=null)
                {
                    centreOfMap = value;

                    LoadMapData();
                }
            }
        }

        public int Zoom
        {
            get
            {
                return this.zoom;
            }
            set
            {
                if (this.zoom != value && value>0 && value<=19)
                {
                    this.zoom = value;

                    LoadMapData();
                }
            }
        }

The method LoadMapData handles all the calls to the Imagery service to get the map uri, followed by a call to the DownloadImageFromUri method, followed by triggering a refresh of the control (ie to get the control to repaint). 

Note that you need to be careful of threading here. You don’t want to be going off and downloading map images on the UI thread (most like the Centre and Zoom properties will be modified when the control is loaded – ie on the UI thread) as this will cause the UI to appear to freeze.  However, you need to issue the command to refresh the control (either Refresh or Invalidate) back on the UI thread.  This can be done by calling Invoke and providing the delegate to invoke on the UI thread. eg

this.Invoke(new System.Threading.ThreadStart(Refresh));

WCF Service Running under Windows 7

WCF Service Running under Windows 7

Yesterday I wanted to add a WCF service to a simple prototype project I was building.  Unfortunately what started off as a simple task ended up in taking much longer than expected (in fact in the end I cheated and went back to a simple asmx web service).  This morning, Dimaz pointed me in the right direction.

Essentially the issue is something to do with the changes in the security model.  I haven’t tracked down exactly what the change in behaviour is but essentially the way to get a WCF service up and running under Windows 7 (at least initially – don’t push this into production until you understand the repercussions) is to set the security mode to None.

Here’s a quick walkthrough of how to reproduce the scenario:

  • Open Visual Studio and create a new WCF Service Application (under the Web node in the New Project dialog)
  • Force a rebuild on this new project – this is so that you can use the Add Service Reference wizard in Visual Studio later on.
  • Add a new Windows Forms project (or WPF if you choose) to your application
  • Right-click the WinForms project node in Solution Explorer and select Add Service Reference.
  • Hit Discover
  • Select the service that is found.
  • Enter the following code either in a button event handler or in the form load event handler for the WinForms project

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
var test = client.GetData(5);

  • Set the WinForms project as the startup project and then hit Run (F5).
  • When the GetData method is invoked either the vshost.exe process will crash (happens on my computer) or you will get an unhandled ProtocolException.  The error that is provided is “The remote server returned an unexpected response: (400) Bad Request.”

Now here’s what you can do to get this running

  • In the web.config file of the WCF Service you need to add a custom binding configuration

<system.serviceModel>
  …
  <wsHttpBinding>
    <binding name="wsHttp">
      <security mode="None" />
    </binding>
  </wsHttpBinding>

  …
</system.serviceModel>

  • You then need to adjust your endpoint declaration to use this binding configuration.

<endpoint binding="wsHttpBinding" bindingConfiguration="wsHttp" … >

  • The last adjustment to be made is to set the Security mode in the WinForms app.config file

<security mode="None">

That’s it, you should be good to go.  Just remember, you’ve set the security mode to None which is not good for production unless you are going over SSL or another secure channel.

Programming 101: Learning to Write Software, Microsoft Style

Programming 101: Learning to Write Software, Microsoft Style

I happened to be poking around on the Microsoft Download site today and came across something which may be of interest to anyone with young kids who may have an interest in being the next Bill Gates of the world.  When I download stuff off the Microsoft download site I often take a look through the list of downloads that other people have also downloaded.  In this case this revealed Microsoft Small Basic (v0.2).  Wondering what this was I downloaded and was pleasantly surprised – its a mini-programming environment, no debugging that I’ve found but the user interface is quite minimal and much less confusing to a newbie than Visual Studio.

image

Initially the screen looks just like any other text editor except for the Run button on the right end of the toolbar.  Note that they’ve kept with F5 to run your application.

As you start to type you get super-cool intellisense – I can’t wait to see this in Visual Studio.  Note that you can move through the intellisense list using the up and down arrow buttons. Each item has a brief description within the intellisense window and then a more detailed description on the right side of the screen.

image

Of course the canonical example is to do Hello World.  Doing this is straight forward with the TextWindow.WriteLine command.  Notice how the information on the right is simple and designed not to confuse, yet informative enough to understand how the method work.  In the second image you can see the error window at the bottom of the screen indicating that there is something wrong with the code you have written.  Whilst this isn’t as informative as some of the debugging information within Visual Studio, again there is enough to point to where the error is located.

imageimage

When this application is run you get a standard console window that renders “Hello World”.  Note that when you press F5 or the Run button the development tool gets coloured over to prevent you modifying code whilst it is executing.  This isn’t the greatest experience, particularly when you are trying to work out where your program is breaking.

 imageimage 

What’s neat is that they’ve integrated a Logo equivalent.  This means that you can code a Turtle to draw things on the screen – definitely a great way to teach kids programming.

image image 

Ok, so my artistic skills aren’t great but you get the idea.  I love what Microsoft is try to do with Small Basic and encourage you to give it a try.

pZing and Tablet PC development

pZing and Tablet PC development

I posted earlier on the Getting Started with Windows Live Tools for Visual Studio whitepaper that is available for download.  You may have noticed that this download was made available via pZing Publishing.  This is a self-publishing service where you can upload a whitepaper, e-book or any other pdf and start to make money out of it. 

The process is relatively simple; simply Sign In with your Windows Live Id, provide some basic details about yourself (including your paypal account to receive payments too), and start uploading pdf documents – you only get charged when someone downloads your pdf! The full process is outlined in the pZing Getting Started guide.

Another book that was recently published via the pZing service was Dr Neil’s Tablet PC Development eBook:

pzing Getting Started with Tablet PC Development

Why isn’t MultiPoint just part of Windows?

Why isn’t MultiPoint just part of Windows?

A question that seems to come up quite frequently about the Windows MultiPoint SDK is whether this can be used to have multiple mouse pointers outside of a specific application? The answer is no.  The current MultiPoint SDK works by essentially hiding the main system cursor and simulating mouse pointers with custom drawn windows (one window for each mouse cursor).  Of course this leads to a bunch of issues around using standard WPF controls and styling in your application – you can’t!  You need to use MultiPoint enabled controls, such as the button and textbox that ship with the sdk, and you need to adjust styles/templates to use MultiPoint properties and events rather than the standard WPF properties/events.


This question does lead into the broader question of why having multiple mouse pointers isn’t available in Windows. There appears to be increasing demand for this, particularly in developing nations where it makes computing much more viable to have multiple people using a single computer. Other new technologies such as Surface are also highlighting how important collaboration and learning is, and how technologies which incorporate multi-touch or multi-cursor can enhance this process.


Will we get multiple pointers in a future version of Windows? Perhaps, but if you look historically at the way applications have always been built you can see that they are built with a single point of focus in mind.  Adding multiple pointers means that Windows would need to support multiple active cursors.  This leads to the issue of how applications that only understand about a single point of activity will be able to handle multiple cursors.  Just “enabling” multiple pointers/cursors doesn’t fix the issue that applications are designed with a single user in mind.


This point applies to using the current MultiPoint SDK.  Don’t just assume that you can MultiPoint enable your application! In most scenarios building a MultiPoint application involves rethinking how your entire application functions to base it on collaboration, rather than single use.

Getting Started with Windows Live Tools for Visual Studio

Getting Started with Windows Live Tools for Visual Studio

At PDC last year there was a lot of discussion around Windows Azure and Live Framework.  One of the pieces in this puzzle are the Live Services which have been around for quite sometime.  The Live Services are available for you to use today – that’s right you can use them in production today.  Better still, there is a set of tools that wrap some of the services to make your life even easier. 

The Windows Live Tools for Visual Studio, November 2008 CTP is available via the Download site.  Whilst getting started with some of the controls is as easy dragging them from the toolbar to the design surface, there are some hidden gems that make these tools really cool.  We’ve put together a getting started guide that is available as a free download via pZing – click on the following image to download the pdf.

pzing Windows Live Tools for Visual Studio

[Updated] The download link now points to the November 2008 CTP

ApplicationPoolIdentity under Windows 7

ApplicationPoolIdentity under Windows 7

This evening I was experimenting with a sample web application we’ve been working on.  After installing the sample I went to the admin page to verify that the database could be connected to.  I got an error that I hadn’t seem previously in any of our testing (on XP and Vista):

System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to failure in retrieving the user’s local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.

After checking all the normal things I thought to poke a bit further into IIS to see if I could work out what was different.  I’ve only been using Windows 7 for a couple of days now but I’m already so used to it that I forget I’m running it and that some things may be different.  It seems that where under Vista our application installs and uses an application pool that uses the NetworkService account, it appears that under Windows 7 it uses the ApplicationPoolIdentity.

image

The trick to getting the site to work was to simply create a different application pool (always good practice) which uses the NetworkService account.

iPhone Killer Application

iPhone Killer Application

Today at Geek Coffee we were considering what the next big killer mobile application is going to be.  Clearly one of the hottest areas for mobile is location awareness.  The Telcos have traditionally been holding the market back in this area – they’ve had the technology to be able to do this for years but unless you want to pay thousands of dollars you’re not able to get at this data. There is a change in the air and in the next couple of years I expect there to be much more in this space. 

Anyhow as part of our brainstorming we came up with a real gem:  There is an increasing number of people complaining about the iphone and there are a large number of people who have had to take a device back for whatever reason.  How about a “Return to Sender” application?  All it does is give you the quickest route from where you currently are to the nearest Apple store, where you can return your device.

image image

I’m sure it would take no more than an hour to knock this up and yet how useful would it be to all you iPhone users…..

Why Windows Mobile?

Why Windows Mobile?

I was just catching up on a couple of blogs and noticed that Paul over at Modaco had an interesting Talking Point where they discuss “What keeps you stuck on Windows Mobile, and what tempts you away?” I tend to agree with a lot of his points but thought I’d add my own commentary, since I think it paints a more realistic story of the future for Windows Mobile.

Pros
– the brilliant Exchange sync story and super productive e-mail client
>> Couldn’t agree more.  The setup, sync and operational side of Email, Calendar and Contacts on Windows Mobile rocks.  Sure the UI looks super dated now and doesn’t work well with touch input but it definitely works.  I suspect that the POOM UI is probably the next cab off the rank for the likes of HTC, Samsung and Sony who all seem to be doing their own custom UIs for the home screen, application navigation etc.

– .net Compact Framework for simple development on the device
>> Again, being a techie I like to be able to write code for my device.  Unfortunately the .NET CF is a little bit heavy for doing serious mobile application development. This definitely contributes to the Windows Mobile problem of being bloated and requiring more hardware than imho it should.

– turn by turn navigation solutions at a low cost
>> Now we are starting to get somewhere – an awesome reason for going with Windows Mobile is there is actually a large number of super cool applications that you can download and/or purchase.  Unfortunately you’ll have to trawl Google to find them as there isn’t a single store to get them from.

CamerAware!
>> Wish we had this app for Australia.

– an OS i’m familiar with at the very deepest level, and that I find productive
>> This is the same “I’ve always been a Windows user” concept.  Unfortunately it’s not necessarily a good reason for sticking with a platform

– a wide variety of devices with a wide variety of form factors
>> It’s definitely arguable that the iphone form factor isn’t for everyone… but it is cool, slick and looks great!

– high resolution cameras
>> Yes, and this will definitely get better.  I’ve always said that one of the things that a Windows Mobile device manufacturer needs to do for their device to be a consumer device is to wack a serious camera in the back.  Take the 5Mb camera on offer on some Sony devices, combined with an actual flash, this device would allow you to dispense of your camera.

– 20 key and 12 key touchscreen input (iPhone NEEDS this imho!)
>> Yes, I’m a big fan of the slide out keyboard too.  That said I’ve seen people type incredibly quickly and accurately on their iphone.

Cons

– App Store!
>> In how many ways and how often can we tell Microsoft this – we need a better process for developers to build and sell their applications.  I don’t care how great the application is, if you can’t sell it then it may as well not have been written

– applications that co-exist with apps I use on my mac, such as 1password touch and Things iphone
>> Sync’ing is a massive reason that Exchange w Windows Mobile is imho the best enterprise mail solution.  Do this with other applications and you can increase this value.  One of the big things that the Windows Mobile platform offers is a rich development environment that has proper support for background threads – this means that you can be sync’ing data, even when your application isn’t in focus.

– Regular, OTA OS updates
>> Again, this is a request that has been iterated again and again and again.  Instead of 2-3 yearly versions, why not release iteratively.  We’ve already seen two versions of the iPhone and it’s anyone’s guess how many more versions we will see before the next version of Windows Mobile?

The challenge for us Windows Mobile enthusiasts is to work out how we can leverage our deep knowledge of the platform and convert it into a compelling reason/feature/application that sets the Windows Mobile platform apart from its competitors.

Virtual Earth Web Services with Mobile and Desktop Images

Virtual Earth Web Services with Mobile and Desktop Images

As I’ve always had an interest in building mobile applications it interested me to see that the Virtual Earth Web Services have support for the generation of images that are optimised for mobile devices.  Curious as to what this meant I took some time to look at the differences between using the Desktop and Mobile values for the DeviceType property when requesting map images from the Imagery service.

image image

Both images here are of Perth, Western Australia (-31.953619,115.858555); both are 200 x 200; both at a zoom level of 12 and both with the MapStyle set to Road.  The difference is that the one of the right was generated using the Desktop value, the one on the right with the Mobile value. Saving these images to the filesystem reveals a significant difference in file/download size.  The desktop image is approximately 88K, where as the mobile image is only around 14.5K.

Interestingly, when you set the MapStyle to Aerial, there is no visible difference in the image, and further when you look at the file size they are exactly the same size.  I’m sure this is probably documented somewhere that the DeviceType doesn’t apply to Aerial images….

Retrieving Map Images from Virtual Earth Web Services

Retrieving Map Images from Virtual Earth Web Services

In my previous post on the Virtual Earth Web Services I showed how you can use the Imagery Service to get the uri of a map, based on the center, zoom, height, width etc.  What I didn’t cover is what you can do with this information. Clearly if you have an control that can accept the uri of an image then you might be able to just set the source property of the control.  However, if you want to do something more “intelligent” with the map, you will most likely have to download the image.  Here’s a simple snippet of code that will take the uri of a map image and return you an in-memory image that you can then manipulate.


private static Image DownloadImageFromUri(string uri)
{
    var mapRequest = WebRequest.Create(new System.Uri(uri));
    WebResponse response = mapRequest.GetResponse();
    MemoryStream responseStream = GetWebUriStream(response);
    return new Bitmap(responseStream);
}


Be warned though: This code downloads the image synchronously – this means that if you execute this code on the UI thread your application will stop responding until the image has downloaded completely.  Following my previous comments on how slow the Imagery service appears to be, I would suggest doing all your Virtual Earth calls on a background thread, simply raising events when the UI needs to be repainted to display new map images.

The Virtual Earth Web Services are Slow

The Virtual Earth Web Services are Slow

I’ve been experimenting with the Virtual Earth Web Service for integrating mapping into a WinForms and/or WPF application.  The set of services, released in the latter half of last year, provides a well defined api for accessing some of the powerful capabilities of the VE platform.

Initially I didn’t set my ambitions too high – I just wanted to render a map.  To get started I needed to reference the four VE services (Geocode, Imagery, Route and Search (actually I only needed the Imagery service initially but added all four so I didn’t have to add them later).  These are all WCF services with details for both staging and production urls detailed here. I also needed to add a reference to the Common service, which is a traditional asmx web service – more information here

With the references to the VE services in place in went looking for the service I needed to call in order to retrieve a single map.  Turns out this is a function called GetMapUri that is part of the Imagery services.  In order to call this service I first needed to generate a token that is used to get access to the service.  This token is based on my credentials which I got after signing up for a staging account (more info here).

TokenSpecification spec = new TokenSpecification()
               {
                   ClientIPAddress = GetIPAddress(),
                   TokenValidityDurationMinutes = 60
               };

CommonService service = new CommonService();
service.Credentials = new NetworkCredential(Properties.Settings.Default.Username,
                                                             Properties.Settings.Default.Password);
virtualEarthToken = service.GetClientToken(spec);

 

Note that accessing the token service takes time, so it is best to cache the token for the full duration that the token is valid for.  In the above code the token is valid for 60 minutes.

The next thing to do is to build up a MapUriRequest object, which includes information about the map (ie center, zoom), as well as the image you want (ie width and height) and of course your token.

MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);

The mapUriResponse contains a property, Uri, that is the address of the image I wanted generated.

One thing I noticed is that this process is very time consuming.  Initially I thought it was the token service – I was calling this every time I wanted to refresh a map.  But after caching the token it was still taking a while for each map uri to be returned (30-60 secs in some cases).  This led me to look at the format of the returned uri.  Essentially the following code will generate a similar string that is much quicker and seems to work [Disclaimer: as I understand it, this is not a supported scenario and whilst it is significantly quicker than calling the imagery service, the format may change without notice]

return string.Format(@"http://staging.tiles.virtualearth.net/api/GetMap.ashx?c={0},{1}&w={2}&h={3}&z={4}", center.Latitude, center.Longitude, width, height, zoomLevel);

The big question is – why is it so slow for the Imagery service to do string.format and return me the uri of the image?  I’m guessing it could be either that it’s running on staging (and thus low resources), that it does more than just a basic string.format or some other reason.  Either way, the fact that it is so slow completely discourages developers from using it and encourages rouge behaviour (eg using String.Format to generate the uri).