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

https://github.com/gistrec/geo-utils-cpp

Header-only C++ library for geographic (lat/lng) calculations: distance, bearing, area, point-in-polygon and path proximity
https://github.com/gistrec/geo-utils-cpp

bearing computational-geometry cpp geodesy geometry geospatial gis gps haversine header-only latitude-longitude navigation point-in-polygon spherical-geometry

Last synced: about 22 hours ago
JSON representation

Header-only C++ library for geographic (lat/lng) calculations: distance, bearing, area, point-in-polygon and path proximity

Awesome Lists containing this project

README

          

# geo-utils-cpp



CI


vcpkg


Code quality


Coverage


Release




C++17


CMake 3.14+


Header-only


Supported platforms


License

Header-only C++17 library for geographic (lat/lng) geometry (no dependencies).

Provides utilities for distance, bearing, polygon area, point-in-polygon, and
path proximity checks on Earth coordinates.

API inspired by Google Maps geometry utilities.
Uses spherical Earth approximation (like Google Maps).

## Features

* **`geo::` spherical functions** — distance, bearing, area, interpolation
* **`geo::` polygon functions** — point-in-polygon, path proximity, distance to segments

## Why use this library?

- Lightweight and header-only (no dependencies)
- Simple API for common GPS/lat-lng calculations
- Suitable for backend, GIS, navigation and tracking systems

## When not to use

- If you need high-precision geodesic calculations on an ellipsoid
- If you need advanced spatial indexing (use S2 / CGAL instead)

## Installation

### FetchContent (recommended)

```cmake
include(FetchContent)

FetchContent_Declare(
GeoUtilsCpp
GIT_REPOSITORY https://github.com/gistrec/geo-utils-cpp.git
GIT_TAG v1.0.1
)
FetchContent_MakeAvailable(GeoUtilsCpp)

target_link_libraries(your_target PRIVATE geo::utils)
```

### vcpkg

```sh
vcpkg install geo-utils-cpp
```

Then in your `CMakeLists.txt`:

```cmake
find_package(GeoUtilsCpp 1.0.1 REQUIRED)
target_link_libraries(your_target PRIVATE geo::utils)
```

### find_package

```cmake
find_package(GeoUtilsCpp 1.0.1 REQUIRED)
target_link_libraries(your_target PRIVATE geo::utils)
```

### Manual

Copy the `include/` directory into your project and add it to your include path.

For more details see [docs/getting-started.md](docs/getting-started.md).

## Usage

```cpp
#include

#include

int main() {
geo::LatLng newYork = { 40.7128, -74.0060 };
geo::LatLng london = { 51.5074, -0.1278 };

double distance = geo::distance_between(newYork, london);
double heading = geo::heading(newYork, london);

std::cout << "Distance: " << distance / 1000.0 << " km\n";
std::cout << "Heading: " << heading << " deg\n";
}
```

## API Reference

See [docs/api.md](docs/api.md) for the full API reference.

## Support

[Please open an issue on GitHub](https://github.com/gistrec/geo-utils-cpp/issues)

## License

Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.