# Coordinates. Where do they come from?

## Table of contents

So, you're thinking about building a new app that heavily relies on navigation, but you're curious about how Google Maps actually works. You're wondering how it's able to display routes and paths so accurately, and maybe you've even entertained the idea of creating your own map. After doing a lot of research, you've managed to connect all the dots and get a pretty good idea of what a map actually is. You're starting to think of it like a huge sheet of paper, but you're still wondering about coordinates - where do they come from, and how are they calculated? There are actually many ways to calculate coordinates, but the key is accuracy. It's fascinating to see how the world comes together on a coordinate system. Currently, we use WGS84 as our standard.

## Finding Coordinates:

There are various methods to locate a point on a piece of paper, but accuracy is always the key.

One simple and interesting way is to take a piece of paper and divide it into two halves vertically, assigning the left half as '0' and the right half as '1'.

Now, divide the paper into two halves horizontally, where the lower half will be '0' and the upper half will be '1'.

Continue dividing the section containing the point into smaller rectangles, each time selecting the rectangle that contains the point. As you divide the paper, assign a binary value to each step. For vertical divisions, assign '0' to the left half and '1' to the right half. For horizontal divisions, assign '0' to the bottom half and '1' to the top half. Once you reach the point, the binary values assigned during the divisions represent its binary coordinate. Convert the obtained binary coordinate to a decimal number to get the point's corresponding decimal coordinate.

So, the odd digits will be latitude and even bits will be longitude.

```
// for latitude
range = 90 - (-90);
precision = binary / (Math.pow(2, 16) - 1);
min + (precision * range);
```

```
// for longitude
range = 180 - (-180);
precision = binary / (Math.pow(2, 16) - 1);
min + (precision * range);
```

That's it.