A pure C implementation of the Geohash algorithm.

Related tags

Utilities libgeohash
Overview

libgeohash

Derek Smith

[email protected]

A static library used for encoding/decoding geohashes.

To use libgeohash just run make. Link libgeohash.a and include geohash.h into your project.

Encode

char* geohash_encode(double lat, double lng, int precision);

Takes in latitude and longitude with a desired precision and returns the correct hash value. If precision < 0 or precision > 20, a default value of 6 will be used.

Decode

GeoCoord geohash_decode(char* hash);

Produces an allocated GeoCoord structure which contains the latitude and longitude that was decoded from the geohash. A GeoCoord also provides the bounding box for the geohash (north, east, south, west).

Neighbors

char** geohash_neighbors(char* hash);

Uses the bounding box declared at hash and calculates the 8 neighboring boxes. An example is show below.

  • ezefx ezs48 ezs49
  • ezefr ezs42 ezs43
  • ezefp ezs40 ezs41

The value returned is an array of char* with length of 8. The neighboring positions of values are shown below with each box representing the index of the array.

  • 7 0 1
  • 6 * 2
  • 5 4 3
You might also like...
An open source re-implementation of LEGO Rock Raiders 🪨⛏

OpenLRR An open source re-implementation of LEGO Rock Raiders (PC). This is created by slowly implementing and replacing game functionality, while rel

GNU project's implementation of the standard C library(with Xuantie RISC-V CPU support).

GNU project's implementation of the standard C library(with Xuantie RISC-V CPU support).

A basic A* implementation showing how to use C++20 modules alongside UWP and C++/WinRT.

Introduction This is a port from an old application that was original written in a mix of C++14, Java and C++/CX. Originaly the goal was to use a simp

C implementation of C++ Utility functions Integer Comparison Macros

C implementation of C++ Utility functions Integer Comparison Macros

✔️The smallest header-only GUI library(4 KLOC) for all platforms
✔️The smallest header-only GUI library(4 KLOC) for all platforms

Welcome to GUI-lite The smallest header-only GUI library (4 KLOC) for all platforms. 中文 Lightweight ✂️ Small: 4,000+ lines of C++ code, zero dependenc

A lean, efficient, accurate geohash encoder and decoder library implemented in C

Geohash encoder/decoder in C A lean, efficient, accurate geohash encoder and decoder library implemented in C. It does not depend on the C standard li

Shamir’s Secret Sharing Algorithm: Shamir’s Secret Sharing is an algorithm in cryptography created by Adi Shamir. The main aim of this algorithm is to divide secret that needs to be encrypted into various unique parts.
Shamir’s Secret Sharing Algorithm: Shamir’s Secret Sharing is an algorithm in cryptography created by Adi Shamir. The main aim of this algorithm is to divide secret that needs to be encrypted into various unique parts.

Shamir-s-Secret-Sharing-Algorithm-Cryptography Shamir’s Secret Sharing Algorithm: Shamir’s Secret Sharing is an algorithm in cryptography created by A

Backroll is a pure Rust implementation of GGPO rollback networking library.

backroll-rs Backroll is a pure Rust implementation of GGPO rollback networking library. Development Status This is still in an early beta stage. At ti

Microshell - a lightweight pure C implementation of shell emulator dedicated for embedded bare-metal systems.
Microshell - a lightweight pure C implementation of shell emulator dedicated for embedded bare-metal systems.

MicroShell Lightweight pure C implementation of virtual shell, compatible with VT100 terminal. Support root tree, run-time mounting paths, global comm

This is a "pure" CPP implementation Database

This is a "pure" CPP implementation Database

Knapsack Encryption Algorithm is the first general public key cryptography algorithm.

Knapsack Encryption Algorithm is the first general public key cryptography algorithm. It is developed by Ralph Merkle and Mertin Hellman in 1978. As it is a Public key cryptography, it needs two different keys. One is Public key which is used for Encryption process and the other one is Private key which is used for Decryption process.

TengineFactory - Algorithm acceleration landing framework, let you complete the development of algorithm at low cost.eg: Facedetect, FaceLandmark..
TengineFactory - Algorithm acceleration landing framework, let you complete the development of algorithm at low cost.eg: Facedetect, FaceLandmark..

简介 随着人工智能的普及,深度学习算法的越来越规整,一套可以低代码并且快速落地并且有定制化解决方案的框架就是一种趋势。为了缩短算法落地周期,降低算法落地门槛是一个必然的方向。 TengineFactory 是由 OPEN AI LAB 自主研发的一套快速,低代码的算法落地框架。我们致力于打造一个完全

Pure C Game Engine

Corange game engine Version 0.8.0 Written in Pure C, SDL and OpenGL. Running Corange is a library, but to take a quick look at some of the things it d

TinyVM is a small, fast, lightweight virtual machine written in pure ANSI C.

TinyVM is a virtual machine with the goal of having a small footprint. Low memory usage, a small amount of code, and a small binary. Building can be

Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).

M*LIB: Generic type-safe Container Library for C language Overview M*LIB (M star lib) is a C library enabling to use generic and type safe container i

Pure C math library for 2D and 3D programming

MATHC MATHC is a simple math library for 2D and 3D programming. Features Vectors (2D, 3D and 4D) (integer type and floating-point type) Quaternions Ma

Pure C Game Engine

Corange game engine Version 0.8.0 Written in Pure C, SDL and OpenGL. Running Corange is a library, but to take a quick look at some of the things it d

Pure C math library for 2D and 3D programming

MATHC MATHC is a simple math library for 2D and 3D programming. Features Vectors (2D, 3D and 4D) (integer type and floating-point type) Quaternions Ma

An HTML5 parsing library in pure C99

Gumbo - A pure-C HTML5 parser. Gumbo is an implementation of the HTML5 parsing algorithm implemented as a pure C99 library with no outside dependencie

Comments
  • Fixing an array boundary overflow issue

    Fixing an array boundary overflow issue

    Just applied a quick fix to the get_neighbor method.

    1. The 1st argument in a call to strncat should have enough place to store the result.
    2. strncat is a bit buggy when _FORTIFY_SOURCE is being used and Xcode uses that when targeting an iOS device. So I have replaced the call to strcat with a safer version of strlcat, which in addition doesn't have that bug.

    More info can be found at: http://www.cocoabuilder.com/archive/xcode/266956-fortify-source-and-strncat-buggy.html

    Another workaround would be to use _FORTIFY_SOURCE=0 but then you'll loose all the sanity checks performed when that is non-zero.

    opened by eploko 1
  • AddressSanitizer: global-buffer-overflow

    AddressSanitizer: global-buffer-overflow

    $ clang -g -fno-omit-frame-pointer -fsanitize=address geohash_test.c geohash.c
    ./a.out
    =================================================================
    ==145148==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55ba71db93e0 at pc 0x55ba71cf095b bp 0x7fff48e04d10 sp 0x7fff48e044c0
    READ of size 33 at 0x55ba71db93e0 thread T0
        #0 0x55ba71cf095a in __interceptor_strlen.part.0 (/home/mpech/libgeohash/a.out+0x6895a)
        #1 0x55ba71d8326f in index_for_char /home/mpech/libgeohash/geohash.c:83:25
        #2 0x55ba71d83f1e in geohash_decode /home/mpech/libgeohash/geohash.c:209:33
        #3 0x55ba71d826cd in main /home/mpech/libgeohash/geohash_test.c:84:22
        #4 0x7f83bb758151 in __libc_start_main (/usr/lib/libc.so.6+0x28151)
        #5 0x55ba71ca919d in _start (/home/mpech/libgeohash/a.out+0x2119d)
    
    0x55ba71db93e0 is located 0 bytes to the right of global variable 'char_map' defined in 'geohash.c:59:13' (0x55ba71db93c0) of size 32
    SUMMARY: AddressSanitizer: global-buffer-overflow (/home/mpech/libgeohash/a.out+0x6895a) in __interceptor_strlen.part.0
    Shadow bytes around the buggy address:
      0x0ab7ce3af220: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
      0x0ab7ce3af230: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
      0x0ab7ce3af240: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
      0x0ab7ce3af250: f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 f9 f9 f9 f9
      0x0ab7ce3af260: 00 00 00 00 f9 f9 f9 f9 00 00 00 00 f9 f9 f9 f9
    =>0x0ab7ce3af270: 00 00 00 00 f9 f9 f9 f9 00 00 00 00[f9]f9 f9 f9
      0x0ab7ce3af280: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
      0x0ab7ce3af290: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
      0x0ab7ce3af2a0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
      0x0ab7ce3af2b0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
      0x0ab7ce3af2c0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
    Shadow byte legend (one shadow byte represents 8 application bytes):
      Addressable:           00
      Partially addressable: 01 02 03 04 05 06 07 
      Heap left redzone:       fa
      Freed heap region:       fd
      Stack left redzone:      f1
      Stack mid redzone:       f2
      Stack right redzone:     f3
      Stack after return:      f5
      Stack use after scope:   f8
      Global redzone:          f9
      Global init order:       f6
      Poisoned by user:        f7
      Container overflow:      fc
      Array cookie:            ac
      Intra object redzone:    bb
      ASan internal:           fe
      Left alloca redzone:     ca
      Right alloca redzone:    cb
      Shadow gap:              cc
    ==145148==ABORTING
    make: *** [Makefile:12: test] Error 1
    
    opened by tankf33der 0
Owner
Urban Airship
Urban Airship
provide SFML Time utilities in pure C++20, no dependencies

SFML-Time-utilities-without-SFML provide SFML Time utilities in pure C++20, no dependencies Example int main() { Clock clock; Sleep(1000);

null 1 Apr 28, 2022
Fast comparison-based sort algorithm

nanosort Algorithm nanosort aims to be a fast comparison-based sorting algorithm, tuned for POD types of reasonably small sizes. nanosort implements a

Arseny Kapoulkine 37 Aug 2, 2022
Backtracking algorithm is constructed with an explicit stack

Backtrack Backtracking algorithm is constructed with an explicit stack PROBLEM STATEMENT: A particular ‘RPA’ firm is in the process of developing a re

null 2 Jan 8, 2022
A CoAP (RFC 7252) implementation in C

libcoap: A C implementation of the Constrained Application Protocol (RFC 7252) Copyright (C) 2010—2021 by Olaf Bergmann [email protected] and others AB

null 657 Sep 29, 2022
Juice the carrots from ウマ娘プリティーダービー (Umamusume Pretty Derby) - Android implementation

Riru-CarrotJuicer Hooks the decryption function in libnative.so of ウマ娘プリティーダービー (Umamusume Pretty Derby), to allow inspecting the packets. For Windows

Huang Yue 27 Aug 9, 2022
This is a simple C++ implementation of plant-like structures defined with bracketed OLsystems.

Tree Hundred This is a simple C++ implementation of plant-like structures defined with bracketed OLsystems, as described in the book The Algorithmic B

null 22 Apr 22, 2022
An implementation of yacc for the janet programming language.

janet-yacc An implementation of yacc for the janet programming language. The implementation is based heavily on https://c9x.me/yacc/. Example from ./e

null 11 Nov 22, 2021
libddwaf is Datadog's implementation of a WAF engine

Datadog's WAF libddwaf is Datadog's implementation of a WAF engine, with a goal of low performance and memory overhead, and embeddability in a wide va

Datadog, Inc. 11 Jul 28, 2022
Small implementation of c++ entity component system inspired by Unity

EntityComponentSystem About This is small implementation of entity component system with C++. The API is heavily inspired by Unity ECS framework, but

Lukas Chodosevičius 2 Oct 13, 2021
Crown (formerly Crowncoin) reference implementation

Crown Core integration/staging tree https://crownplatform.com What is Crown? Crown is an experimental digital currency that enables instant payments t

Crown Platform 4 May 31, 2022