Skip to content

rafamdr/libgeohash36

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libgeohash36

A pure C implementation of Geohash-36.

Geohash-36 encoder creates a hash based in base-36 characters which represents a coordinate (latitude and longitude).

Example: the coordinate {51.504444, -0.086666} produces bdrdC26BqH

More about Geohash-36

[1] http://en.wikipedia.org/wiki/Geohash-36

[2] http://en.wikipedia.org/wiki/Geohash

[3] http://geohash.org/

Usage

int geohash36_encode(double latitude_, double longitude_, char * outBuffer_, int numCharacters_);

Encodes desired latitude/longitude in Geohash-36 representation with a desired length.

Example:

   const int num_chars = 10;
   char geohash36_buffer[num_chars + 1];
   double latitude = 51.504444;
   double longitude = -0.086666;
   
   geohash36_encode(latitude, longitude, geohash36_buffer, num_chars);
   
   //Output: geohash36_buffer = "bdrdC26BqH";

int geohash36_decode(char * buffer_, int bufferSize_, double * outLatitude_, double * outLongitude_);

Decodes a Geohash-36 string.

Example:

   const char geohash36_buffer[] = "bdrdC26BqH";
   int num_chars = sizeof(geohash36_buffer) - 1;
   double outLatitude = 0, outLongitude = 0;
   
   geohash36_decode(geohash36_buffer, num_chars, &outLatitude, &outLongitude);

   //Output: outLatitude = 51.504444; outLongitude = -0.086666;

void geohash36_getPrecisionInMeters(int numCharacters_, double * lat_prec, double * long_prec);

Gets the precision (in meters) for latitude and longitude, given the number of characters in Geohash-36.

Example:

   int num_chars = 10
   double lat_prec, long_prec;
   
   geohash36_getPrecisionInMeters(num_chars, &lat_prec, &long_prec);
   
   //Output: lat_prec = 0.165480; long_prec = 0.330961;

char * geohash36_getNeighbor(char * buffer_, int bufferSize_, char * outBuffer_, uint16_t direction_);

Gets a neighbor Geohash-36 given a input hash and a direction (north, northeast, etc).

Example:

   const char geohash36_buffer[] = "bdrdC26BqH";
   int num_chars = sizeof(geohash36_buffer) - 1;
   char geohash36_buffer_neighbor[num_chars];
   
   geohash36_getNeighbor(geohash36_buffer, num_chars, geohash36_buffer_neighbor, GEO36_NEIGHBORS_DIR_NORTHEAST));
   
   //Output: geohash36_buffer_neighbor = "bdrdC26Bq8";

Contributing

  1. Fork it ( https://github.com/rafamdr/libgeohash36/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Author

Copyright & License

Please refer to the COPYING.md and LICENSE.md file.

About

A pure C implementation of Geohash-36

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published