GeoLite2++  v0.0.1-2036
C++ API for MaxMind's GeoLite2 Database
Usage

Query the GeoLite2 database and return a JSON string with the details for the given address:

#include <GeoLite2PP.hpp>
...
GeoLite2PP::DB db( "/opt/stuff/GeoLite2-City.mmdb" );
std::string json_ = db.lookup( "216.58.216.163" );
std::cout << json << std::endl;

Query the GeoLite2 database and return very specific field values for the given address:

#include <GeoLite2PP.hpp>
...
GeoLite2PP::DB db( "/opt/stuff/GeoLite2-City.mmdb" );
std::string city = db.get_field( "216.58.216.163", GeoLite2PP::VCStr { "city" , "names" , "en" } );
std::string country = db.get_field( "216.58.216.163", GeoLite2PP::VCStr { "country" , "names" , "en" } );
std::string latitude = db.get_field( "216.58.216.163", GeoLite2PP::VCStr { "location", "latitude" } );

The fields in the vector (e.g., "city", "names", "en") are used to traverse the structures and return exact values. This traversal path can be determined by comparing against the .json output from the previous call, part of which is:

1 {
2  "city" :
3  {
4  "names" :
5  {
6  "de" : "Mountain View",
7  "en" : "Mountain View",
8  "fr" : "Mountain View",
9  "ja" : "マウンテンビュー",
10  "ru" : "Маунтин-Вью",
11  "zh-CN" : "芒廷维尤"
12  }
13  },

Calling db.get_field() with a vector containing "city", "names", "en" would return the English name for the given city, or "Mountain View" in this example.

For additional details and methods that can be called to query MaxMind's GeoLite2 IP address database, please refer to the documentation for GeoLite2PP::DB. For example:

API Description
GeoLite2PP::DB Class to talk to the GeoLite2 database.
GeoLite2PP::DB::DB() Constructor to gain access to the database.
GeoLite2PP::DB::lookup() Look up an IP address and return all the information as a JSON string.
GeoLite2PP::DB::get_all_fields() Look up an IP address and return a std::map of many fields.