Closed abhishrek closed 2 years ago
You may have caught an issue in my implementation. I'll have to dig deeper into this. I will say if you're just using this library the difference doesn't really matter, as it decodes to approximately the same input used to encode it.
However for keeping with spec and comparability with other libraries then this could be a problem. I don't remember what I used as reference when writing this code, but I'll have to look into this.
Hot take, I believe I'm correct in using >
rather than >=
.
According to the IEEE research paper explaining geohashes, they say:
If the target coordinate value is greater than the pivot, a 1 bit is appended to the overall set of bits; otherwise a 0 bit is appended.
Greater than, not greater than or equal to.
Way to give me a heart attack today 😅
But hopefully that answers that question! If you're satisfied I'll close out this issue.
Thanks,
This solves my issue, I will update my code to use >
only. You can close the issue.
Actually I was using geoFirestore
lib which uses (or tests only ? uses) geokit
for hashes, but I also needed to get neighbors of a geohash, and the resource I mentioned provides a function for this, so I started using that instead of geokit
, and I noticed the difference, while checking for compatibility.
If geokit
can provide functions to get neighbors out-of-the-box as well, it would be great.
Get points around a lat/lng is out of the scope of this project. I'd advise implementing your own, or you could probably do something like import {geohashQueries} from 'geofirestore-core/dist/utils'
. Good luck!
I was not asking for "points around lat/lng", I was asking for neighboring geoHashes of a given geoHash.
Sorry, that is what I meant. And the geohashQueries
function takes the lat lng and generated geohashes around it. You can use it as reference => https://github.com/MichaelSolati/geofirestore-core/blob/ea0fff8feea10800025005cfdf34eb339e96e635/src/utils.ts#L257
I was using a geohashing function explained in https://www.movable-type.co.uk/scripts/geohash.html
It's almost the same as this geokit lib. Except for the coordinates that lie on exact boundary defined as 180/(2^n) i.e : 90, 45, 22.5, ... and so on
Reason being that the function that calculates hash differs by comparison condition
>
vs>=
https://github.com/MichaelSolati/geokit/blob/5b805a7c42362a408f3a6bf21f62ddba9b257a2c/src/functions/hash.ts#L36I see you used
>
here, but the code i meationed above uses>=
So my question is are both correct ? or is there any standard for such cases ?
For example : For a coord
{45.0, 45.0}
, this geokit lib gives the hashszzzzzzzzz
, but the other code i mentioned above givesv000000000