2014-02-09 27 views

回答

0

請閱讀README文檔https://github.com/davetroy/geohash-js ... 在JavaScript中,您可以通過調用例如JavaScript來創建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 

即三點現在描述了更大的區域。正如在自述文件中提到的那樣,這個較大的框不是在原始(較高分辨率)框中居中的 - 爲此,您需要通過使用例如計算器來計算相鄰(頂部,底部,左側,右側)地理雜亂。

mygh_top= calculateAdjacent(mygh, 'top') 

看看geohash-demo.js的來源,它顯示了一個例子。

0

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')); 
}