Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to base4 #30

Open
ppKrauss opened this issue Nov 27, 2018 · 4 comments
Open

Add option to base4 #30

ppKrauss opened this issue Nov 27, 2018 · 4 comments

Comments

@ppKrauss
Copy link

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) ... 
@sunng87
Copy link
Owner

sunng87 commented Nov 28, 2018

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.

@ppKrauss
Copy link
Author

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 added a commit to ppKrauss/node-geohash that referenced this issue Nov 28, 2018
@sunng87
Copy link
Owner

sunng87 commented Nov 28, 2018

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

@ppKrauss
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants