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
- Host: GitHub
- URL: https://github.com/gistrec/geo-utils-cpp
- Owner: gistrec
- License: apache-2.0
- Created: 2019-11-13T11:01:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2026-05-07T19:57:03.000Z (5 days ago)
- Last Synced: 2026-05-07T20:37:56.690Z (5 days ago)
- Topics: bearing, computational-geometry, cpp, geodesy, geometry, geospatial, gis, gps, haversine, header-only, latitude-longitude, navigation, point-in-polygon, spherical-geometry
- Language: C++
- Homepage:
- Size: 165 KB
- Stars: 42
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Notice: NOTICE
Awesome Lists containing this project
- Awesome-Geospatial - geo-utils-cpp - Header-only C++17 library for spherical (lat/lng) geometry: distance, bearing, area, point-in-polygon. (C++)
- awesome-open-geoscience - geo-utils-cpp - in-polygon. (Software / Geospatial)
README
# geo-utils-cpp
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.