Ezequiel Santos
iOS Developer & Creative Technologist # 🚗 Tech: Mapping with GPS Coordinates

Greetings,

It's been quite some time since I've written anything, and I just logged in to find that there have been over some visits to my blog since I last posted. I'm guessing that some post of mine has become a reference on Google or something like that. But it has motivated me to start writing again with a focus on mobile development (especially iOS), Internet of Things, and a bit on innovation and hackathons.

With that introduction out of the way, let's get to the topic at hand. Have you ever noticed in taxi apps or in Uber, when the car is coming, it moves smoothly along the street and makes the turns just right? Here's an example: Recently I had to do something similar, and for anyone who's worked with maps, you know that you don't get that car tilt data, you just get the coordinates, the latitude and longitude of the car.

To make things easier to understand, let's imagine a Cartesian plane with some mathematical function that describes the movement of our coordinate point.

All we have are the points. In a simplified manner, imagine that with each car movement, we have a new point that contains an X and a Y, in our case, the latitude and longitude.

Now, let's take a look at a practical example: Suppose our car on the map went through point A and then through point B, as shown below: To calculate the distance, we would use the classic Pythagorean theorem formula for the hypotenuse of a triangle.

A0 = differences in the X axis B0 = differences in the Y axis

We can use A0 and B0 to calculate the angular coefficient of the line that passes through A and B:

m = tg α = yB – yA = B0 xB – xA A0

Knowing the tangent of this angle, we can calculate the angle using the arctangent.

Thinking programmatically (entering iOS now, but the mathematical abstraction would be the same for any language), we have an object called CLLocationCoordinate2D that has the properties latitude and longitude.

In C (Objective-C supports the math.h library), we have the function to calculate the arctangent `atan(value)`, in our case it would be B0/A0, our angular coefficient (tangent) for value.

However, we have to compensate for the domain of the arctangent function. Remembering a bit of Calculus I, the domain of the Arctangent function is [-π/2, π/2], we can even take a peek at Wikipedia: As our angle will come in terms of π, we subtract the result from pi/2.

To make it easier to understand, let's imagine a Cartesian plane with some arbitrary mathematical function that describes the movement of our coordinate point.

All we have are the points.

X, Y coordinate system (Cartesian plane)

We would have something like this, thinking about a map, converting a point to a coordinate.

Map of geographic coordinates

Simplifying, let's imagine that with each movement of the car, I have a new point that contains an X and a Y, in our case, the latitude and longitude. 