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;
35 len = max(0, min(
int(maxlen_), len));
37 ulon = (
unsigned long long)(floor(lon/loneps) + shift),
38 ulat = (
unsigned long long)(floor(lat/lateps) + shift);
39 char geohash1[maxlen_];
41 for (
unsigned i = 0; i < 5 * unsigned(len);) {
43 byte = (byte << 1) +
unsigned((ulon & mask_) != 0);
46 byte = (byte << 1) +
unsigned((ulat & mask_) != 0);
51 geohash1[(i/5)-1] = lcdigits_[byte];
56 copy(geohash1, geohash1 + len, geohash.begin());
60 int& len,
bool centerp) {
61 static const real shift = ldexp(
real(1), 45);
62 static const real loneps = 180 / shift;
63 static const real lateps = 90 / shift;
64 int len1 = min(
int(maxlen_),
int(geohash.length()));
66 ((toupper(geohash[0]) ==
'I' &&
67 toupper(geohash[1]) ==
'N' &&
68 toupper(geohash[2]) ==
'V') ||
70 (toupper(geohash[1]) ==
'A' &&
71 toupper(geohash[0]) ==
'N' &&
72 toupper(geohash[2]) ==
'N'))) {
76 unsigned long long ulon = 0, ulat = 0;
77 for (
unsigned k = 0, j = 0; k < unsigned(len1); ++k) {
80 throw GeographicErr(
"Illegal character in geohash " + geohash);
81 for (
unsigned m = 16; m; m >>= 1) {
83 ulon = (ulon << 1) +
unsigned((byte & m) != 0);
85 ulat = (ulat << 1) +
unsigned((byte & m) != 0);
89 ulon <<= 1; ulat <<= 1;
94 int s = 5 * (maxlen_ - len1);
97 lon = ulon * loneps - 180;
98 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.