Geohash: Difference between revisions
Content added Content deleted
m (→{{header|J}}: slight efficiency gain and an observation about rounding) |
(→{{header|J}}: extra credit) |
||
Line 362: | Line 362: | ||
11 geohash 57.64911 10.40744 |
11 geohash 57.64911 10.40744 |
||
u4pruydqqvj</syntaxhighlight> |
u4pruydqqvj</syntaxhighlight> |
||
And, going the other direction (producing a min and max lat and long value for the geohash): |
|||
<syntaxhighlight lang=J>hsahoeg=: {{ |
|||
bits=: |.|:0,~_2]\,(5#2)#:gdigits i.y |
|||
scale=: %2^{:$bits |
|||
lo=: scale*#.bits |
|||
hi=: scale*(2^1+1 0*2|#y)+#.bits |
|||
0.5*_180+360*lo,.hi |
|||
}}</syntaxhighlight> |
|||
This gives us: |
|||
<syntaxhighlight lang=J> hsahoeg 'gc' |
|||
50.625 56.25 |
|||
_5.625 0 |
|||
hsahoeg 'gcpue5hp4' |
|||
51.4337 51.4337 |
|||
_0.107074 _0.107052 |
|||
hsahoeg 'u4pruydqqvj' |
|||
57.6491 57.6491 |
|||
5.20372 5.20372</syntaxhighlight> |
|||
Or |
|||
<syntaxhighlight lang=J> 9!:11]10 NB. display 10 digits of floating point precision |
|||
hsahoeg 'gcpue5hp4' |
|||
51.43369675 51.43373966 |
|||
_0.1070737839 _0.1070523262 |
|||
hsahoeg 'u4pruydqqvj' |
|||
57.64910996 57.6491113 |
|||
5.203719512 5.203720182</syntaxhighlight> |
|||
=={{header|jq}}== |
=={{header|jq}}== |