An open API service indexing awesome lists of open source software.

https://github.com/felipe-sant/maps

🌎 Development of an application that generates two random points in Brazil and simulates a flight between these points, taking into account the curvature of the Earth. It uses an IBGE API to control the coordinates and identify the state of Brazil through which the plane is passing.
https://github.com/felipe-sant/maps

ibge-api maps typescript

Last synced: about 1 year ago
JSON representation

🌎 Development of an application that generates two random points in Brazil and simulates a flight between these points, taking into account the curvature of the Earth. It uses an IBGE API to control the coordinates and identify the state of Brazil through which the plane is passing.

Awesome Lists containing this project

README

          



# 🌎 Maps πŸ—ΊοΈ

![typescript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)

Development of an application that generates two random points in Brazil and simulates a flight between these points, taking into account the curvature of the Earth. It uses an IBGE API to control the coordinates and identify the state of Brazil through which the plane is passing.

> [Visit the website here!](https://front-maps.vercel.app/)

## βš™οΈ How to run

1. Clone the repository and start the submodules.

git clone https://github.com/felipe-sant/Maps.git
cd Maps
git submodule update --init --recursive

2. Download the dependencies in both repositories.

cd Back
npm install
cd ..

cd Front
npm install

3. Run both repositories with the command:

npm start

## πŸ“˜ Contents covered

- Calculation of geodesic lines;
- Implementation of external APIs.
- Map rendering;


Calculation of geodesic lines

#### 1. Conversion to Radians

The latitude and longitude angles, given in degrees, are converted to radians:

lat₁ = startPoint.lat Γ— Ο€/180
lon₁ = startPoint.lon Γ— Ο€/180

latβ‚‚ = endPoint.lat Γ— Ο€/180
lonβ‚‚ = endPoint.lon Γ— Ο€/180

#### 2. Calculation of the Angle Between Points (Δσ)

The central angle (Δσ) between the two points on the sphere is computed using the dot product in 3D space:

Δσ = arccos(sin(lat₁) β‹… sin(latβ‚‚) + cos(lat₁) β‹… cos(latβ‚‚) β‹… cos(lonβ‚‚ - lon₁))

if Δσ = 0, the points are identical, and the function directly returns the starting point.

#### 3. Interpolation Coefficients (π‘Ž and 𝑏)

The coefficients π‘Ž and 𝑏 determine the contribution of each point in the interpolation, using trigonometric functions:

π‘Ž = sin((1 - 𝑑) β‹… Δσ) / sin(Δσ)

𝑏 = sin(𝑑 β‹… Δσ) / sin(Δσ)

Here:

- 𝑑 is the interpolation parameter (0 corresponds to the starting point, and 1 corresponds to the ending point).

- sin(Ξ”πœŽ) normalizes the coefficients to ensure correct interpolation along the spherical arc.

#### 4. Interpolation in 3D Space

The points are treated as 3D vectors projected onto the sphere, with coordinates:

π‘₯ = π‘Ž β‹… cos(lat₁) β‹… cos(lon₁) + 𝑏 β‹… cos(latβ‚‚) β‹… cos(lonβ‚‚)

𝑦 = π‘Ž β‹… cos(lat₁) β‹… sin(lon₁) + 𝑏 β‹… cos(latβ‚‚) β‹… sin(lonβ‚‚)

𝑧 = π‘Ž β‹… sin(lat₁) + 𝑏 β‹… sin(latβ‚‚)

#### 5. Conversion Back to Latitude and Longitude

The interpolated coordinates (π‘₯, 𝑦, 𝑧) are converted back to latitude and longitude:

lat = arctan2(𝑧, √(π‘₯Β² + 𝑦²))

lon = arctan2(𝑦, π‘₯)

Finally, the values are converted from radians to degrees:

lat = lat Γ— 180/Ο€
lon = lon Γ— 180/Ο€

#### Mathematical Summary of the Function

The interpolation calculates the intermediate point 𝑑 along the spherical arc between two points on the Earth's surface, with:

1. Δσ determining the angular distance between the points.
2. π‘Ž and 𝑏 weighting the vectors of the start and end points.
3. The resulting 3D vectors being converted back into geographic coordinates.

This enables smooth movement of a point between two locations while maintaining the geodesic trajectory.


Implementation of external APIs

In this project, I used an external API from **IBGE** to implement geographic meshes. The API was utilized to identify geographic coordinates and retrieve information about the state or municipality a specific coordinate references. This integration ensured accurate mapping of coordinates to administrative regions.






Map rendering

One of the key topics covered in this project was map rendering, using the **Leaflet** library. With Leaflet, it was possible not only to render interactive maps but also to manage the coordinates of points on the map, ensuring precise control over the location and interaction of geographic elements. This approach enabled the creation of dynamic and functional visualizations for efficiently exploring spatial data.



developed by @felipe-sant