Add option to base4
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) ...
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.
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 ...
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
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?