examples/example-Geohash.cpp
Go to the documentation of this file.
1 // Example of using the GeographicLib::Geohash class
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <exception>
6 #include <string>
8 
9 using namespace std;
10 using namespace GeographicLib;
11 
12 int main() {
13  try {
14  {
15  // Sample forward calculation
16  double lat = 57.64911, lon = 10.40744; // Jutland (the wikipedia example)
17  string geohash;
18  int maxlen = Geohash::GeohashLength(1.0e-5);
19  for (int len = 0; len <= maxlen; ++len) {
20  Geohash::Forward(lat, lon, len, geohash);
21  cout << len << " " << geohash << "\n";
22  }
23  }
24  {
25  // Sample reverse calculation
26  string geohash = "u4pruydqqvj";
27  double lat, lon;
28  cout << fixed;
29  for (unsigned i = 0; i <= geohash.length(); ++i) {
30  int len;
31  Geohash::Reverse(geohash.substr(0, i), lat, lon, len);
32  cout << setprecision(max(0, Geohash::DecimalPrecision(len)))
33  << len << " " << lat << " " << lon << "\n";
34  }
35  }
36  }
37  catch (const exception& e) {
38  cerr << "Caught exception: " << e.what() << "\n";
39  return 1;
40  }
41 }
#define max(a, b)
Definition: datatypes.h:20
static const double lat
Definition: Half.h:150
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const double lon
size_t len(handle h)
Definition: pytypes.h:1514
Header for GeographicLib::Geohash class.


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:02