17 const char*
const Geohash::lcdigits_ =
"0123456789bcdefghjkmnpqrstuvwxyz";
18 const char*
const Geohash::ucdigits_ =
"0123456789BCDEFGHJKMNPQRSTUVWXYZ";
21 static const real shift = ldexp(
real(1), 45);
22 static const real loneps = 180 / shift;
23 static const real lateps = 90 / shift;
26 +
"d not in [-90d, 90d]");
31 if (lat == 90) lat -= lateps / 2;
33 if (lon == 180) lon = -180;
36 len = max(0, min(
int(maxlen_), len));
38 ulon = (
unsigned long long)(floor(lon/loneps) + shift),
39 ulat = (
unsigned long long)(floor(lat/lateps) + shift);
40 char geohash1[maxlen_];
42 for (
unsigned i = 0; i < 5 * unsigned(len);) {
44 byte = (byte << 1) +
unsigned((ulon & mask_) != 0);
47 byte = (byte << 1) +
unsigned((ulat & mask_) != 0);
52 geohash1[(i/5)-1] = lcdigits_[byte];
57 copy(geohash1, geohash1 + len, geohash.begin());
61 int& len,
bool centerp) {
62 static const real shift = ldexp(
real(1), 45);
63 static const real loneps = 180 / shift;
64 static const real lateps = 90 / shift;
65 int len1 = min(
int(maxlen_),
int(geohash.length()));
67 ((toupper(geohash[0]) ==
'I' &&
68 toupper(geohash[1]) ==
'N' &&
69 toupper(geohash[2]) ==
'V') ||
71 (toupper(geohash[1]) ==
'A' &&
72 toupper(geohash[0]) ==
'N' &&
73 toupper(geohash[2]) ==
'N'))) {
77 unsigned long long ulon = 0, ulat = 0;
78 for (
unsigned k = 0, j = 0; k < unsigned(len1); ++k) {
81 throw GeographicErr(
"Illegal character in geohash " + geohash);
82 for (
unsigned m = 16; m; m >>= 1) {
84 ulon = (ulon << 1) +
unsigned((byte & m) != 0);
86 ulat = (ulat << 1) +
unsigned((byte & m) != 0);
90 ulon <<= 1; ulat <<= 1;
95 int s = 5 * (maxlen_ - len1);
98 lon = ulon * loneps - 180;
99 lat = ulat * lateps - 90;
static T AngNormalize(T x)
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
static void Forward(real lat, real lon, int len, std::string &geohash)
Exception handling for GeographicLib.
static int lookup(const std::string &s, char c)
static void Reverse(const std::string &geohash, real &lat, real &lon, int &len, bool centerp=true)
Header for GeographicLib::Geohash class.