17 const char*
const Geohash::lcdigits_ =
"0123456789bcdefghjkmnpqrstuvwxyz";
18 const char*
const Geohash::ucdigits_ =
"0123456789BCDEFGHJKMNPQRSTUVWXYZ";
22 static const real shift = ldexp(
real(1), 45);
23 static const real loneps = 180 / shift;
24 static const real lateps = 90 / shift;
27 +
"d not in [-90d, 90d]");
28 if (isnan(lat) || isnan(lon)) {
32 if (lat == 90) lat -= lateps / 2;
34 if (lon == 180) lon = -180;
37 len = max(0, min(
int(maxlen_), len));
39 ulon = (
unsigned long long)(floor(lon/loneps) + shift),
40 ulat = (
unsigned long long)(floor(lat/lateps) + shift);
41 char geohash1[maxlen_];
43 for (
unsigned i = 0; i < 5 * unsigned(len);) {
45 byte = (
byte << 1) +
unsigned((ulon & mask_) != 0);
48 byte = (
byte << 1) +
unsigned((ulat & mask_) != 0);
53 geohash1[(i/5)-1] = lcdigits_[
byte];
58 copy(geohash1, geohash1 + len, geohash.begin());
62 int& len,
bool centerp) {
63 static const real shift = ldexp(
real(1), 45);
64 static const real loneps = 180 / shift;
65 static const real lateps = 90 / shift;
66 int len1 = min(
int(maxlen_),
int(geohash.length()));
68 ((toupper(geohash[0]) ==
'I' &&
69 toupper(geohash[1]) ==
'N' &&
70 toupper(geohash[2]) ==
'V') ||
72 (toupper(geohash[1]) ==
'A' &&
73 toupper(geohash[0]) ==
'N' &&
74 toupper(geohash[2]) ==
'N'))) {
78 unsigned long long ulon = 0, ulat = 0;
79 for (
unsigned k = 0, j = 0; k < unsigned(len1); ++k) {
82 throw GeographicErr(
"Illegal character in geohash " + geohash);
83 for (
unsigned m = 16; m; m >>= 1) {
85 ulon = (ulon << 1) +
unsigned((
byte & m) != 0);
87 ulat = (ulat << 1) +
unsigned((
byte & m) != 0);
91 ulon <<= 1; ulat <<= 1;
96 int s = 5 * (maxlen_ - len1);
99 lon = ulon * loneps - 180;
100 lat = ulat * lateps - 90;