Coordinates, Doubles and a Localisation Bug

I was recently driven crazy by a particularly annoying bug whilst developing a feature of Foundbite that allows you to view what other’s have uploaded in a certain location.

In the app you scroll over the area in the world you want to view and the app then sends a simple request to our Azure hosted API to get the foundbites in a given location rect. The request looks a bit like this:

http://api.foundbite.co/SearchFoundbites?latMin=-79.2&lonMin=-179.232&latMax=79.343&lonMax=179.99

It’s constructed by getting the coordinates and simply using double.ToString() for each individual lat/long.

Testing on my Windows Phone device it all worked fine but a select group of beta testers reported that whenever they visited the page and tried to load some bites the map was remaining blank and the web request was failing every time.

This was confusing to say the least and I spent a whole day trying to work out what was wrong, including trying different versions of the app but came up empty.

At my wits end (see above) I consulted with a fellow Windows Phone developer, George Spyrou, who had incidentally fixed the exact same bug in his app that very day.

It turns out, all the users that were reporting this bug were based in European countries and had different cultures on their phones. These cultures use a “,” instead of a “.” in decimal values and therefore when the app was composing the URL in these cultures it looked like this:

http://api.foundbite.co/SearchFoundbites?latMin=-79,2&lonMin=-179,232&latMax=79,343&lonMax=179,99

It doesn’t look all the different if you can glance at it, but the commas in the URL invalidate it and the request will return an error every time without giving you much of an idea as to why.

Thankfully when I became aware of it, there was a simple fix at hand; instead of using double.ToString() you should use double.ToString(CultureInfo.InvariantCulture) which ensures the culture is ignored.

A simple bug but hopefully this’ll prevent other devs falling into a similar trap when incorporating GPS Coordinates into URL’s.

Advertisements

What I learnt building a gimmicky app for Windows Phone…

Before taking the startup route with Mendzapp and subsequent development of Foundbite, it was really just a professional front for my Windows Phone app development. The first few apps I developed, Travelnapp and YuleTile, I knew weren’t going to make me rich in the very early days of Windows Phone, but I won’t deny hoping for at least a bit of money, I was a lowly student after-all. YuleTile made some money for myself and the Railway Children charity but we’re only talking a couple of hundred pounds really.

Browsing the api site, Programmable Web, I came across Face.com – a company that ran a service that analysed photos, recognised faces and even went as far as guessing how old they were. It was pretty impressive stuff and I immediately came up with a concept for an app that I though could really be quite good.

I remembered an app called Fit or Fugly that had been demonstrated to me on the iPhone by a friend. The app, which told you how fit or fugly you or your friends were, was able to judge the degree of unfortunate looks by working out the distance ratios between your nose and eyes. It was a fairly polished app but there wasn’t actually anything that clever (technically) about it. You snapped a picture of a friend’s face and simply dragged and dropped markers on their face where their mouth, nose and eyes were. The app then made a big show of processing the data and gave you a percentage score (I’ve since conveniently forgotten my score).

Gimmicky yes, but at the time people were really liking these fart style apps and the developer, Ed Nash, went on to do amazingly well from it with over 2 million downloads worldwide according to the app description. At £0.69, that’s quite a lot of money!

I saw how much he’d made from something so basic and got the dollar signs in my eyes and set about making VizAge for Windows Phone. Even though Windows Phone has far less users I figured I could still make a pretty penny.

Alas, my thoughts of earning a quick buck were not to be.

It didn’t come down to the app really, it was given some strong praise by Richard at WPCentral, was featured on the marketplace, got about 4.4/5 stars on average, 11,000 downloads and took a slightly fun and odd take to metro design.

I think the real problem was the different ways users behave on Windows Phone compared to iOS when it comes to buying apps due to the lack of trial mode. In the case of Fit of Fugly, this meant that people who were shown the app by a friend and wanted to try it on their phone just shelled out the inconsequential £0.69 for the app without batting an eyelid (iPhone users are younger an wealthier don’t you know).

On Windows Phone the trial mode makes the experience far better for users, less money wasted on apps that don’t do what they say, but for makers of gimmicky apps like myself at the time, it meant that people might try it for a bit and then decide it’s fun but not worth the money and never buy the full app.

For the trial mode in VizAge, I allowed the user to take and get the results for 3 images before they were then prompted to upgrade if they wanted to take more or compare themselves to some famous faces. In all honesty, it probably wasn’t a good enough value proposition for most and about 7% decided to go ahead and upgrade.

Don’t get me wrong, the app was by no means a failure (surprising given its power to offend if it got the ages wrong) as I recouped my investment (before the Face.com API was shut down by Facebook, – booo!) and I learnt a hell of a lot. However, it was clear to me that unlike the stories you read about in the paper of people getting rich “overnight” with their “hit” fart app it really isn’t all that easy and the apps gold rush where people will buy anything from a virtual pint to a lightsaber are truly over.

I figured I should concentrate on developing something more meaningful that won’t make me an app millionaire overnight and that is something far more useful and enjoyable for users to be a part of and for me to develop. With that in my mind, I started developing Foundbite.

If you disagree or had similar experiences, I’d love to hear from you: jamesmundy@mendzapp.com.

Lessons Learnt Using the Windows Phone Camera API

I’ve been working with the Windows Phone camera API (PhotoCaptureDevice) a lot recently for Foundbite, some of the things I’ve learnt:

Not every Windows Phone has flash

I didn’t realise this until recently when testing with the cheap as chips Nokia Lumia 520. It’s a great device for the price but you need to add a check to your camera code to make sure other flash modes are available before manipulating it.

Here’s a method to get the available flash states and another to check if flash is available for the current device (ie: if there is one or less flash states).

public bool IsFlashAvailable()
{
List<FlashState> flashStates = GetAvailableFlashStates().ToList();
return (flashStates.Count > 1);
}

public IReadOnlyList<FlashState> GetAvailableFlashStates()
{
IReadOnlyList<object> rawValueList = PhotoCaptureDevice.GetSupportedPropertyValues(Device.SensorLocation, KnownCameraPhotoProperties.FlashMode);
List<FlashState> flashStates = new List<FlashState>(rawValueList.Count);foreach (object rawValue in rawValueList) flashStates.Add((FlashState)(uint)rawValue);
return flashStates.AsReadOnly();
}

Update #1: Jay Benett ponts out that this can be done in a far simpler way than I have using LINQ’s .Any() https://twitter.com/JayTBennett/status/370221811423670272

Update #2: Just realised this update 1 method won’t work as even if there isn’t a flash on the device there will still be FlashState.Off in the list.

Update #3:After more discussion, it turns out there is a way to do it using Jay’s method: https://twitter.com/scottisafool/status/371913405080547328. I’m going to stop updating this post now.

In some regions the camera shutter sound can’t be turned off

Foundbite allows you to take a picture at the same time as recording audio so it wouldn’t be ideal if you could hear the shutter sound in every sound clip. It is possible to turn the sound off but in some regions of the world it’s a legal necessity to have this sound on.

It’s therefore a necessity to check that you can turn the sound off before doing so:

private void disableShutterSound()
{
if (!(bool)this.Device.GetProperty(KnownCameraGeneralProperties.IsShutterSoundRequiredForRegion))
this.Device.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, false);
}

It’s possible to turn off the flash that happens when you focus the camera

This setting is called the FocusIlluminationMode and can easily be changed, much like FlashMode, between Auto, On and Off.

Here’s the code to get the current value and change it:

public FocusIlluminationMode GetCurrentFocusIlluminatonMode()
{
return (FocusIlluminationMode)(uint)Device.GetProperty(KnownCameraPhotoProperties.FocusIlluminationMode);
}

public void SetIlluminationMode(FocusIlluminationMode mode)
{
Device.SetProperty(KnownCameraPhotoProperties.FocusIlluminationMode, mode);
}

It’s worth nothing that you should check the flash is available before changing this mode too!
Hopefully these will be helpful and save some time for others playing around with the camera.