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:

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:,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.