const z = require('z-curve');
z.encode(lat, lng, scala);
z.decode(z_val);
在浏览器中测试: https://npm.runkit.com/z-curve
Encode a pair of latitude and longitude values into a z-curve.
const z = require('z-curve');
z.encode(32.05, 118.78333) === 471947;
Decode a hash string into pair of latitude and longitude values. A javascript object is returned with lat
and lng
keys.
const z = require('z-curve');
z.decode(471947);
// {
// lat: 32.16796875,
// lng: 118.65234375
// }
测试环境:
- CPU: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (8 核心 16 线程)
- Memory: 72 GB 2667 MHz DDR4
- GPU: Radeon Pro 580X 8 GB
Geohash#encode(precision=9) x 3,215,635 ops/sec ±0.36% (91 runs sampled)
Geohash#encode(precision=10) x 2,878,923 ops/sec ±0.67% (95 runs sampled)
Geohash#encode(precision=11) x 2,682,806 ops/sec ±0.41% (96 runs sampled)
Geohash#encode(precision=12) x 2,485,485 ops/sec ±0.40% (94 runs sampled)
Geohash#encode(precision=13) x 2,244,528 ops/sec ±0.41% (95 runs sampled)
Geohash#encode(precision=14) x 2,097,478 ops/sec ±0.55% (95 runs sampled)
Geohash#encode(precision=15) x 2,027,248 ops/sec ±0.65% (86 runs sampled)
Geohash#encode(precision=16) x 1,978,832 ops/sec ±0.34% (98 runs sampled)
Geohash#encode(precision=17) x 1,896,373 ops/sec ±0.43% (91 runs sampled)
Geohash#decode(precision=9) x 5,080,911 ops/sec ±0.41% (96 runs sampled)
Geohash#decode(precision=10) x 4,590,824 ops/sec ±0.50% (93 runs sampled)
Geohash#decode(precision=11) x 4,096,476 ops/sec ±0.41% (92 runs sampled)
Geohash#decode(precision=12) x 3,912,653 ops/sec ±0.44% (97 runs sampled)
Geohash#decode(precision=13) x 3,601,804 ops/sec ±0.49% (93 runs sampled)
Geohash#decode(precision=14) x 3,375,785 ops/sec ±0.37% (94 runs sampled)
Geohash#decode(precision=15) x 3,096,618 ops/sec ±0.44% (92 runs sampled)
Geohash#decode(precision=16) x 2,942,242 ops/sec ±0.53% (92 runs sampled)
Geohash#decode(precision=17) x 2,754,588 ops/sec ±0.41% (94 runs sampled)
Z#encode(scale=0) x 30,013,706 ops/sec ±0.43% (95 runs sampled)
Z#decode(scale=0) x 23,199,739 ops/sec ±1.22% (92 runs sampled)
- GeoHash Node 实现: https://github.com/sunng87/node-geohash
- IEEE 754 工具: https://baseconvert.com/ieee-754-floating-point