Skip to content

gistrec/geo-utils-cpp

Repository files navigation

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)

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

vcpkg install geo-utils-cpp

Then in your CMakeLists.txt:

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

find_package

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.

Usage

#include <iostream>

#include <geo/spherical.hpp>

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 for the full API reference.

Support

Please open an issue on GitHub

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Contributors