node-geohash icon indicating copy to clipboard operation
node-geohash copied to clipboard

Add option to base4

Open ppKrauss opened this issue 7 years ago • 4 comments

The structure of the Geohash is a base4 hierarchy: powers of 4 in the spatial representation (grid cell divided into 4 cels each iteration).

In applications that need to access "the full hierarchy", is important to use base4 (2 bits). In the Javascript code is only a inclusion of one parameter in the Encode method:

  • @param {Number|String} latitude
  • @param {Number|String} longitude
  • @param {Number} numberOfChars
  • @param {boolean} useBase4 (default is false)
var encode = function (latitude, longitude, numberOfChars, useBase4) {
...
var maxBits = (useBase4===true)? 2: 5;
...
    if (bits === maxBits) ... 

ppKrauss avatar Nov 27 '18 14:11 ppKrauss

Sounds good to me. Could you please send a pull request for this?

Also I suggest to create a new function like encodeBase4 for this behavior.

sunng87 avatar Nov 28 '18 01:11 sunng87

Hi @sunng87 , thanks (!). Another issue to the encodeBase4 and this option in the encode parametrization: "auto precision" and default numberOfChars, will be affected... Any suggestion to adapt?

As base4 digits are 2 bits length and base32 digits are 5 bits, the factor is 5/2=2.5 ...

ppKrauss avatar Nov 28 '18 09:11 ppKrauss

Hi @ppKrauss , while encode and encodeBase4 shares same encoing logic, they don't have to share parameters and meaning of them. The base4 one could have its own signature and shouldn't affect current implementation of encode

sunng87 avatar Nov 28 '18 13:11 sunng87

Ok, but is important to reuse code.. The parameter useBase4 can be a private variable of the Class... How do you want to declare it as private variable?

ppKrauss avatar Nov 28 '18 14:11 ppKrauss