File: example-GARS.cpp

package info (click to toggle)
geographiclib 2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,572 kB
  • sloc: cpp: 27,765; sh: 5,463; makefile: 695; python: 12; ansic: 10
file content (39 lines) | stat: -rw-r--r-- 939 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Example of using the GeographicLib::GARS class

#include <iostream>
#include <iomanip>
#include <exception>
#include <string>
#include <GeographicLib/GARS.hpp>

using namespace std;
using namespace GeographicLib;

int main() {
  try {
    {
      // Sample forward calculation
      double lat = 57.64911, lon = 10.40744; // Jutland
      string gars;
      for (int prec = 0; prec <= 2; ++prec) {
        GARS::Forward(lat, lon, prec, gars);
        cout << prec << " " << gars << "\n";
      }
    }
    {
      // Sample reverse calculation
      string gars = "381NH45";
      double lat, lon;
      cout << fixed;
      for (int len = 5; len <= int(gars.size()); ++len) {
        int prec;
        GARS::Reverse(gars.substr(0, len), lat, lon, prec);
        cout << prec << " " << lat << " " << lon << "\n";
      }
    }
  }
  catch (const exception& e) {
    cerr << "Caught exception: " << e.what() << "\n";
    return 1;
  }
}