2

我使用来自https://github.com/davetroy/geohash-js的代码 但我不知道如何计算给定 geohashcode 的周围 geohashcode。我需要在 php 和 javascript 中使用函数来计算它们。有没有人有这样的代码或一些方法来解决这个问题?

4

2 回答 2

1

阅读https://github.com/davetroy/geohash-js上的 README ...在 javascript 中,您可以通过调用 eg 创建 GeoHash

mygh= encodeGeoHash( 53.1, -0.24 );

这会给你一个像:'gcry4d91zt7n'的值,如果你解码这个:

mydecoded= decodeGeoHash(mygh);

你得到一个对象,其中包含:

Object {latitude: Array[3], longitude: Array[3]}
latitude: Array[3]
0: 53.099999986588955
1: 53.10000015422702
2: 53.10000007040799

longitude: Array[3]
0: -0.24000003933906555
1: -0.2399997040629387
2: -0.23999987170100212 

如果您只是将 geohash 截断为“gcry”,那么您已经降低了分辨率并且对 decodeGeoHash 的调用将返回:

Object {latitude: Array[3], longitude: Array[3]}
latitude: Array[3]
0: 53.0859375
1: 53.26171875
2: 53.173828125

longitude: Array[3]
0: -0.3515625
1: 0
2: -0.17578125

即这三点现在描述了一个更大的区域。正如自述文件中提到的,这个较大的框不在原始(更高分辨率)框的中心 - 因为您需要使用例如计算相邻(顶部、底部、左侧、右侧)geohashes

mygh_top= calculateAdjacent( mygh, 'top')

查看 geohash-demo.js 的源代码,其中显示了一个示例。

于 2014-02-09T13:33:45.033 回答
1

https://github.com/davetroy/geohash-js/blob/master/geohash-demo.js#L63有例子:

GeoHashBox.prototype.showNeighbors = function () {
var geohashPrefix = this.geohash.substr(0,this.geohash.length-1);

this.neighbors.top = new GeoHashBox(calculateAdjacent(this.geohash, 'top'));
this.neighbors.bottom = new GeoHashBox(calculateAdjacent(this.geohash, 'bottom'));
this.neighbors.right = new GeoHashBox(calculateAdjacent(this.geohash, 'right'));
this.neighbors.left = new GeoHashBox(calculateAdjacent(this.geohash, 'left'));
this.neighbors.topleft = new GeoHashBox(calculateAdjacent(this.neighbors.left.geohash, 'top'));
this.neighbors.topright = new GeoHashBox(calculateAdjacent(this.neighbors.right.geohash, 'top'));
this.neighbors.bottomright = new GeoHashBox(calculateAdjacent(this.neighbors.right.geohash, 'bottom'));
this.neighbors.bottomleft = new GeoHashBox(calculateAdjacent(this.neighbors.left.geohash, 'bottom'));
}
于 2017-01-23T21:26:54.110 回答