Map Application Demystified

A few years ago, when I bought my first smart phone, one of the applications which I used more frequently was Google Maps. That was the time when I moved to a new city. And in the initial few days, wherever I go I had Google Maps open. After setting my destination, as I follow the route I keep wondering how this ‘Magical’ application works. But today, being a Developer at ThoughtWorks and having got opportunities to work on applications that use maps, I would say a map application is just a combination of a few moving parts which does the magic!

Though there are applications which show just a static image of map with little user interaction, a typical map application is one that allows users to interact with it. A good example is the app used for booking cabs. One can set his / her pickup point or choose the current location as the pickup point, pan the map, zoom in / out, see the cabs’ location (These are called Markers, which are nothing but images which mark points on the map), and after boarding the cab, see the route travelled (These are called Polylines, which are sequence of points).

Lets consider interactive map application. There are four primary players: User, who does the interactions; Device, which translates the user’s interactions into a language that the application can understand and shoulders some of the user’s task, say getting the current location; The Application itself; A Black Box, which provides the map images, addresses and lots more. We will get back to this Black Box in a short while. With this information, I will introduce the first two moving parts behind a map application. First one is the device itself. The device must be equipped enough to get user interactions and user location (using GPS or Network Provider). Second one is the piece of software (client-side library, used internally by the application) which does the heavy lifting work in presenting the maps, markers, polylines, etc. to the user.

In the process of looking into other moving parts, I shall demystify the black box mentioned earlier as well. There are so many data getting shown on a map application. First the map itself. There are even different images for the same location. One image show the geography, another shows transit information, another shows a dark image indicating its night time! And many many more. If you have noticed carefully, the entire map that’s being displayed is not a single image. Rather its made of many small images which together appears as a single image. These small images are called Tiles – Square shaped 256 x 256 pixel PNG images. And the component that provides these tiles is called the Tile Server. This is one of the little boxes within the black box.

Second, given an address the application correctly points out the location on the map. This process is called Geocoding – It basically means converting a human readable address to geographic coordinates. Third, the reverse process of Geocoding. A typical example is getting one’s current location. The GPS hardware in the device provides just the geographic coordinates. But the application shows the location in human readable address. This process is called Reverse Geocoding. And these are services (APIs) provided by a single or two different components. To keep it simple, lets have just tile server, Geocoding API and Reverse Geocoding API in the black box. However, there can be many other components and services involved depending on the complexity of the application.

So now that we know the various components involved, lets look at the tasks done by the client side library. As mentioned earlier, the client side library is the one that gels the user interactions and other components. Some of the work done by it are described below:

  • Request the tile server to provide the tiles for the region which the user currently views.
  • Handles zooming: Zoom level can be analogous to the height from which the user views a region. If the user zooms in, (s)he expects to get a closer look, and there by expects to see more details on the map. If the user zooms out, he / she probably wants a hawk eye view of the area rather than the intricate details. To support this, the tile server has tiles of different zoom levels. And the client library takes the responsibility of getting the tiles of appropriate zoom level.
  • Allows panning: Whenever the user pans the map, the library calculates the missing tiles that are required to fill the view and requests those from the tile server.
  • Provides the user the ability to add markers.
  • Does the groundwork of converting a point from device (screen) coordinate system to geographic coordinate system and vice versa.

So the next time when you use any map application, I believe you wouldn’t be considering it to be a magic box.


Coffee Making: The Functional Way!

    Coffee making is an art! And there is a guy near my home who is good at that. He runs a coffee stall where he makes nice flavors of coffee with beautiful art works on those. And recently I just dropped in to the coffee shop while returing home from my work. As he was making a cup of coffee for me by pressing some combination of buttons on a coffee machine he had, I was just wondering the way people used to make coffee a few years back. They used to do that in a very imperative way!

cup makeCoffee (cup, coffeePowder, sweetness, canAddMilk, tempDegrees, creamFlavor) {
        Add coffeePowder amount of coffee powder in to cup
        Add sweetness amount of sugar in to cup.
        if (canAddMilk is yes)
            Fill the cup with milk
            Fill the cup with water
        while(temperature of mixture is less than tempDegrees) {
            Heat the contents of cup
        return cup

So there we go. The step-by-step procedure for making a cup of coffee. However, coffee vendors nowadays make coffee by the press of a few buttons.

cupWithCoffeePowder = addCoffeePowder(cup, quantity)
cupWithSugar = addSugar(cupWithCoffeePowder, quantity)
cupWithCoffee = fillCup(cupWithSugar, choiceOfMilkOrWater)
cupWithHotCoffee = heatMixture(cupWithCoffee, temperature)

And that’s it. Each function above is equivalent to a button on the coffee vending machine which the coffee vendor pressed.

And the above two ways of coffee making are synonymous to imperative programming vs functional programming. On careful analysis we can notice that, in the former method we specify how to make a cup of coffee. And in the latter we simply say what to do, i.e. addCoffeePowder, addSugar, fillCup, heatMixture (And the internal working of each step is handled by the machine – user has to just press the buttons and wait for his coffee). Just like how the coffee machine provides us with built in buttons and abstracts out what it does behind the scenes, a functional programming language also provides us with a basic set of functions with which we could accomplish our task or use those as building blocks for creating new functions.

And now I am gonna go and make a coffee for myself – in the functional way 😉

Coded for an Integrated Development Environment

To say more about it, it is my first project in my college career. It was done with my self interest. The IDE was coded in GTK+. Initially I had very little knowledge on creating it. I didn’t even know how an IDE works, ie. how it compiles the code, displays the compilation message and executes the program. Then I started to browse the web, and finally ended up with GTK+. First I tried creating some small windows with some buttons and simulating a simple dialog box. Once i became familiar with the language, I started coding for the IDE.

Since I was doing my project in Linux environment (Ubuntu), it was easy for me to make the system calls. I ended up compiling and executing the code by making the respective system calls. That’s something which I learnt new.

Finally,  completed my IDE in 2 months span. Though the application has minimal features, and merely no portability, I learnt quite a lot from this project. I learnt a new language, how to work on a project, how to timeline our period of work, etc. Indeed that was a kick start for me to get involved in projects.