娴呭嚭GEOHASH绠楁硶
Posted 鐖变笂涓€娈甸噹鐮?/a>
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了娴呭嚭GEOHASH绠楁硶相关的知识,希望对你有一定的参考价值。
棰樺浘: from Yaroslav Shuraev from pexel
濡備粖瓒婃潵瓒婂鐨勭敓娲绘湇鍔℃秾鐜板嚭鏉ワ紝濡傛淮婊淬€佺編鍥€侀タ浜嗕箞浠ュ強鍚勭O2O銆?杩欎簺鏈嶅姟鐨勫熀鏈壒鐐归兘鏄熀浜庡湴鐞嗕綅缃甃ocation Based Services(LBS)锛屼細鏍规嵁鐢ㄦ埛鎵€澶勭殑浣嶇疆鍘绘彁渚涙湇鍔¢€夐」锛屽叾涓緢閲嶈鐨勪竴鐐瑰氨鏄窛绂伙紝璺濈鏄嚦鍏抽噸瑕佺殑涓€椤癸紝姣曠珶涓嶈兘鍏佽婊存淮娲句竴杈?0KM澶栫殑杞︽潵鎺ヤ綘锛屼綘浼氬嵏杞界殑銆?/span>
涓句釜馃尠锛屼粖鏅氳寖鑰佹澘閭€璇峰績浠殑濮戝鍘诲悆楗紝蹇冪粏鐨勮寖鑰佹澘鎷呭績濂崇涓婁簡涓€澶╃彮锛屼笉甯屾湜璧板お澶氳矾锛屼簬鏄悳绱簡濂崇鍏徃闄勮繎鐨勯鍘咃紝骞堕€夋嫨浜嗗叾涓竴瀹舵牸璋冧笉閿欑殑瑗块鍘呫€備复杩戠害瀹氭椂闂达紝鑼冭€佹澘浣跨敤婊存淮棰勭害浜嗕竴杈嗛檮杩戠殑杞︼紝褰撹寖鑰佹澘韪忎笂杞︾殑閭d竴鍒伙紝涓€椤跨編濡欑殑鏅氶鍗冲皢寮€濮嬨€傝繖閲岄鍘呯殑閫夋嫨涓庢淳杞︾殑閫昏緫閮芥槸LBS澶ф樉韬墜鐨勫湴鏂?/span>
璺濈璁$畻
姝e涓婇潰鐨勪緥瀛愶紝蹇呴』涓虹敤鎴锋壘鍑烘煇鍦扮偣闄勮繎鐨勯鍘呫€佷负鐢ㄦ埛鍖归厤闄勮繎鐨勫徃鏈猴紝杩欎簺閮芥槸瑕佹眰璁$畻鍑轰袱鑰呬箣闂寸殑璺濈鎴栬€呰繎浼艰窛绂汇€?/span>
绠€鍗曠矖鏆? 灏嗘暟鎹簱涓鍘呭拰鐢ㄦ埛閫夋嫨鐨勫湴鐐逛竴涓€璁$畻锛屽啀鏍规嵁璁$畻缁撴灉(璺濈)杩涜杩囨护銆?鎹婊存淮鏈夋垚鐧句笂鍗冧竾鍙告満锛屾洿涓嶈璇寸編鍥㈢殑灏忓悆搴楀浜嗭紝杩欐牱鐨勬€ц兘鑲畾鏄笉婊¤冻闇€姹傜殑
鎻愬崌鐗? 涓洪鍘呮墦涓婃爣绛撅紝闅跺睘浜庡摢涓煄甯傘€佸摢涓尯锛屽厛鏍规嵁鏍囩绛涗竴閬嶏紝鏁版嵁閲忓皬浜嗗緢澶氾紝浣嗘槸鍩庡競鍜屽尯鍩熻竟鐣屽浣曞鐞嗗憿銆?鑰屼笖婊存淮鐨勫徃鏈烘槸鍔ㄦ€佺殑銆?/span>
杩涢樁鐗? 鏃ュ父鎴戜滑鏌ヨ閮芥槸鏈変竴涓煡璇㈢储寮曪紝鎵€浠ュ緢蹇紝濡傛灉鎴戜滑鑳戒负鍏跺缓绔嬬储寮曪紝閭f煡璇㈢殑鏃跺€欏氨浼氬揩寰堝浜嗭紝浣嗗湴鐞嗕綅缃槸浜岀淮鐨勶紝鎴戜滑涓哄叾寤虹珛绱㈠紩寰堥夯鐑︺€?缂虹偣鏄缓绔嬬储寮曟棤娉曚负浜岀淮鏂瑰悜鍚屾椂寤虹珛绱㈠紩銆備簬鏄嚭鐜颁簡绌洪棿绱㈠紩鐨勬蹇?nbsp;
绌洪棿绱㈠紩
铏界劧鎴戜滑鎯冲埌浜嗙储寮曠殑鏂瑰紡浼氭瀬澶у湴鎻愰珮鏌ヨ鏁堢巼锛屼絾鏅€氱殑绱㈠紩鏂瑰紡鏃犳硶婊¤冻鎴戜滑瀵逛簩缁翠笘鐣屽缓绔嬬储寮曠殑闇€姹傦紝鍥犳鎴戜滑闇€瑕佷竴绉嶇壒娈婄殑绱㈠紩----绌洪棿绱㈠紩
鍏充簬绌洪棿绱㈠紩锛屽弬鑰冧富娴佹暟鎹簱鍙互鍙戠幇鍏朵富瑕佹€濇兂鏄?R鏍?/span>涓嶩ash鎬濇兂銆?渚嬪Redis涓嶮ongoDb閮介噰鐢ㄤ簡Hash鐨勬€濇兂鏉ュ疄鐜扮┖闂寸储寮曪紝 鑰孧ySQL涓嶱ostgreSQL閮介噰鐢ㄤ簡R鏍戠殑鎬濇兂鏉ヨВ鍐崇┖闂撮棶棰樸€?/span>
R鏍? 閲囩敤澶ф濂楀皬妗嗙殑鎬濇兂锛屽鏋滈渶瑕佹壘涓€涓锛屽氨鍙互鏍规嵁灞傜骇鍏崇郴锛屼竴涓涓€涓鐨勪竴灞備竴灞傜殑鎵撅紝鎵ц璧锋潵涓嶣鏍戠被浼笺€傚叧浜嶳鏍戜笉鍋氳繃澶氬睍寮€銆?/span>
GeoHash: 閲囩敤灏嗕簩缁翠俊鎭檷缁村埌涓€缁磋搴︼紝鍐嶄粠涓€缁磋搴﹀埄鐢ㄤ紶缁熺殑鎬濊矾鍘昏繘琛岀┖闂寸储寮曠殑璁$畻銆?/span>
GeoHash
GeoHash鐨勬€濊矾鏄皢缁忕含搴︿簩缁翠俊鎭浆涓轰竴缁翠俊鎭紝鍗冲皢缁忕含搴﹁浆鎹负鏅€氬瓧绗︿覆濡?(33.256754,116.876543) --> wtgj5w4ysu6c, 涔嬪悗瀵逛簬涓や釜鐐圭殑璺濈鍒ゅ畾鍙互绠€鍗曞湴鏍规嵁GeoHash鍚庣殑瀛楃涓插幓瀵规瘮銆?/span>
EnGeoHash
涓轰粈涔圙eoHash鍙互鏈夎繖鏍风殑榄斿姏锛屾垜浠厛鏉ョ湅涓€涓嬪畠鏄浣曡绠桯ash瀛楃涓茬殑銆?/span>
绾害璁$畻: 鎴戜滑瀵圭含搴︿竴鐩磋繘琛屼簩鍒嗚绠?/span>
[-90,90] 33.256754钀藉湪涓偣0鐨勫彸渚э紝鎴戜滑鍙?
[0,90] 33.256754钀藉湪涓偣45鐨勫乏渚э紝鎴戜滑鍙?
[0,45] 33.256754钀藉湪涓偣22.5鐨勫彸渚э紝鎴戜滑鍙?
[22.5,45] 33.256754钀藉湪涓偣33.75鐨勫乏渚э紝鎴戜滑鍙?
[22.5,33.75] 33.256754钀藉湪涓偣28.125鐨勫彸渚э紝鎴戜滑鍙?
.....缁х画璁$畻
缁忚繃绾害鐨勮绠楋紝鎴戜滑寰楀埌缁撴灉1010111101
缁忓害璁$畻
[-180,180] 116.876543钀藉湪涓偣0鐨勫彸渚э紝鎴戜滑鍙?
[0,180] 116.876543钀藉湪涓偣90鐨勫彸渚э紝鎴戜滑鍙?
[90,180] 116.876543钀藉湪涓偣135鐨勫乏渚э紝鎴戜滑鍙?
[90,135] 116.876543钀藉湪涓偣112.5鐨勫彸渚э紝鎴戜滑鍙?
[112.5,135] 116.876543钀藉湪涓偣123.75鐨勫乏渚э紝鎴戜滑鍙?
.....缁х画璁$畻
缁忚繃缁忓害鐨勮绠楋紝鎴戜滑寰楀埌缁撴灉1101001100
Hash璁$畻
濡傛灉鎴戜滑鎶婄淮搴﹀拰缁忓害鐨勮绠楃粨鏋滀氦鍙夌硡鍚堝湪涓€璧凤紝璁╃粡搴﹀崰鎹鏁帮紝绾害鍗犳嵁鍋舵暟鍒欑粨鏋滀负
鍚屾椂鎴戜滑浣跨敤0-9銆乤-z(鍘绘帀ailo)杩?2涓瓧姣嶆瀯鎴恇ase32浣嶇紪鐮佸涓嬪浘銆?/span>
32浣嶇紪鐮佸嵆5浣嶄簩杩涘埗00000-11111锛屽洜姝ゅ皢涓婅堪鐨勮绠楃粨鏋滄寜5浣嶄竴鍒嗗壊骞惰浆鎹负10杩涘埗寰楀埌11100-->28锛?11001-->25锛?01111-->15锛?10001-->17
鍐嶆寜鐓ase32缂栫爜鑾峰彇鍒板搴旂殑缁撴灉涓簑tgj
鍘籫eohash.org缃戠珯杩涜楠岃瘉鍙戠幇鎴戜滑鐨勭粨鏋滄槸姝g‘鐨勶紝鍙槸绮惧害浣嶆暟涓嶅悓鑰屽凡
鐪嬪浘璇磋瘽瑙i噴鍘熺悊
鎴戜滑闇€瑕佸皢浜岀淮鐨勪俊鎭彉鍒颁竴缁翠笂鍘诲姣旓紝瀵逛簬浜屽垎鎴戜滑姣旇緝瀹规槗鐞嗚В锛屽埄鐢ㄤ笉鏂殑浜屽垎鍘昏繎浼肩殑閫艰繎鐩爣鎵€鍦ㄧ殑浣嶇疆銆?浣嗘槸褰撶粡搴︺€佺含搴︿袱涓簩鍒嗘弶鏉傚湪涓€璧锋椂锛屾垜浠槸鎬庢牱鍋氱殑鍛€?鎴栬涓嬮潰杩欏紶鍥炬洿瀹规槗璇存槑杩欎釜闂
鎴戜滑寰堝鏄撳彂鐜拌繖寮犲浘鍏跺疄灏辨槸鍒╃敤鍥涗釜璞¢檺鐨勬柟寮忔潵浣跨敤浜屽垎鐨勬€濇兂锛屽洓涓薄闄愬垎鍒唬琛?01銆?0銆?0銆?1锛岀劧鍚庢牴鎹潗鏍囩殑浣嶇疆涓嶆柇杩涜璞¢檺鍒ゆ柇锛屾瘡涓€娆$殑鍒ゆ柇閮芥槸鍩轰簬鍓嶄竴娆$殑鍒ゆ柇缁撴灉锛屾渶鍚庡緱鍒伴偅涓蹭簩杩涘埗鏁板瓧锛屽啀杩涜32base浣嶇殑Hash璁$畻锛屼粠鑰屽緱鍒版渶缁堢殑缁撴灉銆?span class="mq-68">鏄笉鏄湁鐐瑰儚淇勭綏鏂濞冨▋锛屾瘡涓潗鏍囩郴閮藉垎涓?涓薄闄愶紝姣忎釜璞¢檺鍏跺疄鍙堟槸涓€涓皬鍧愭爣绯伙紝鍙堝彲浠ュ垎涓?涓薄闄愶紝鏃犵┓鏃犲敖銆?/span>
鍏跺疄鏃犺鏄厛缁忕含搴︿簩鍒嗗啀鎻夋潅杩樻槸鐩存帴杩涜璞¢檺鍒ゆ柇鑾峰彇01銆?0銆?0銆?1鐨勭粨鏋滐紝鍏舵湰璐ㄩ兘鏄涓や釜缁村害(缁忕含涓や釜鏂瑰悜)鐨勪笉鏂簩鍒嗐€?/span>
鏍规嵁鍥剧墖鎴戜滑鍙互鍙戠幇锛屾棤璁轰袱涓簩杩涘埗涓茬殑绮惧害鏄惁鐩稿悓锛屼粠宸﹀悜鍙筹紝鐩稿悓浣嶆暟瓒婂锛屽垯鍏剁粡绾害澶ф鐜囧垯瓒婃帴杩戯紝鍥犱负涓や釜鍧愭爣浠庡ぇ鍧愭爣绯诲埌灏忓潗鏍囩郴涓€鐩磋惤鍦ㄧ浉鍚岀殑璞¢檺銆傜涓€浣嶄笉鍚岀殑浣嶆暟瓒婇潬鍓嶏紝鍒欏叾涓嶅悓璞¢檺鎵€鍦ㄧ殑鍧愭爣绯昏秺澶э紝涓よ€呬箣闂寸殑瀹為檯鐗╃悊璺濈宸窛鍒欐湁鍙兘瓒婂ぇ锛屽綋鐒朵篃涓嶆槸缁濆鐨勶紝姣斿涓や釜鐐瑰潗钀藉湪鏌愪釜璞¢檺绮惧害鐨勪袱渚э紝濡?-0.000001,0)涓?0.000001,0)銆?/span>
DeGeoHash
鏃㈢劧鏈塆eoHash璁$畻锛岄偅涔堣偗瀹氭湁瀵瑰簲鐨勮В瀵嗚绠椼€傜敱浜庡埄鐢ㄧ殑鏄簩鍒嗙殑鎬濇兂锛屽洜姝よВ瀵嗗洖鍘诲彧鏄€艰繎鐐癸紝鑰屼笉鏄湡姝g殑鐐广€?瑙e瘑閫昏緫姣旇緝绠€鍗?/span>
灏咷eoHash鐨勫瓧绗︿覆杞负浜岃繘鍒讹紝wtgj-->11100110010111110001
鍒嗗埆鎻愬彇缁忕含搴︼紝缁忓害1101001100锛岀含搴?010111101
瀵圭粡绾害鍒嗗埆鎵ц鍙嶄簩鍒嗭紝浠ョ含搴︿负渚?/span>
鍙嶄簩鍒?/span>
101011 1101
绗竴浣嶆槸1琛ㄧず浣嶄簬0-90
绗簩浣嶆槸0琛ㄧず浣嶄簬0-45
绗笁浣嶆槸1琛ㄧず浣嶄簬22.5-45
绗洓浣嶆槸0琛ㄧず浣嶄簬22.5-33.75
绗簲浣嶆槸1琛ㄧず浣嶄簬28.125-33.75
绗叚浣嶆槸1琛ㄧず浣嶄簬30.9375-33.75
绗竷浣嶆槸1琛ㄧず浣嶄簬32.34375-33.75
绗叓浣嶆槸1琛ㄧず浣嶄簬33.046875-33.75
绗節浣嶆槸0琛ㄧず浣嶄簬33.046875-33.3984375
绗崄浣嶆槸1琛ㄧず浣嶄簬33.22265625-33.3984375
鍥犳鎴戜滑鏈€鍚庡彲浠ヨ緭鍑虹含搴︿负33.310546875=(33.22265625+33.3984375)/2
璁$畻缁撴灉涓庤绠楀墠鐨?3.256754鏈夊樊璺濓紝濡傛灉鎻愰珮绮惧害鐨勮瘽宸窛浼氭洿灏忋€?/span>
濡傛灉浣跨敤wtgj5w4ysu6c杩欐牱鐨勭簿搴﹁繘琛孌eGeoHash璁$畻寰楀嚭鐨勭含搴︿负33.25675408355892锛屽叾涓?3.256754宸窛灏遍潪甯稿皬浜嗭紝褰撶劧楂樼簿搴︾殑璁$畻蹇呯劧鑰楁椂涓庢€ц兘瑕佹眰浼氭洿楂樸€?/span>
閭诲煙璁$畻
閭诲煙璁$畻鍗充笂涓嬪乏鍙?涓柟鍚戠殑璁$畻锛屽乏涓婅繖涓€绫诲彲浠ュ厛鍚戜笂锛屽啀鍚戝乏杩涜璁$畻銆?/span>
鏃㈢劧鎴戜滑鏄缁忕含涓や釜鏂瑰悜涓嶆柇杩涜浜屽垎寰楀埌鐨勬渶缁堢粨鏋滐紝閭d箞閭诲煙璁$畻锛屾垜浠寲绠€涓€涓嬶紝浠ュ悜宸︿负渚嬨€傚弬鑰冪湅鍥捐璇濈殑閭e紶璞¢檺鍥俱€?/span>
鍋囪鎴戜滑寰楀埌鐨勭粡搴︿簩杩涘埗涓蹭负111(鏈€鍙充笂瑙?锛屽叾鍚戝乏涓€浣嶅嵆涓?10锛屼笖绾害涓嶅彉銆?/span>
濡傛灉鍐嶅悜宸︾Щ鍔ㄤ竴娆★紝鍒欏彉涓?01锛屽叾瀹炴槸鍦ㄥ仛鍑忔硶杩愮畻銆傚洜姝ゅ彲浠ユ€荤粨鍑?/span>
宸﹀彸绉诲姩涓虹粡搴﹁绠楋紝鍚戝乏涓哄噺涓€锛屽悜鍙充负鍔犱竴
涓婁笅绉诲姩涓虹含搴﹁绠楋紝鍚戜笂涓哄姞涓€锛屽悜涓嬩负鍑忎竴
娉ㄦ剰杈圭晫锛屽閬?00鍑忎竴鍒欏彉涓?11锛岄亣111鍔犱竴鍙樹负000锛屽洜涓哄湴鐞冩槸鍦嗙殑锛屽垎鐣岀嚎鍙槸鎴戜滑浜轰负瀹氫箟鐨勶紝鏈€灏忓€煎拰鏈€澶у€煎叾瀹炴槸杩為€氱殑銆?nbsp;
鎬荤粨
鐩镐俊鐪嬪埌杩欓噷鑱槑鐨勪綘宸茬粡瀵笹eoHash鏈夊ぇ姒傜殑浜嗚В浜嗭紝GeoHash鍙互婊¤冻缁濆ぇ澶氭暟鐨凩BS鏈嶅姟瑕佹眰锛岃涓嶇劧涔熶笉浼氳繘鍏edis杩欐牱鐨勫熀纭€鏈嶅姟宸ュ叿銆?nbsp;
鍙傝€?/strong>
[绌洪棿绱㈠紩Spatial Indexing](https://zhuanlan.zhihu.com/p/38597148)
[娣卞叆娴呭嚭绌洪棿绱㈠紩锛氫负浠€涔堥渶瑕佺┖闂寸储寮昡(https://www.cnblogs.com/LBSer/p/3392491.html)
[绌洪棿绱㈠紩 - 鍚勬暟鎹簱绌洪棿绱㈠紩浣跨敤鎶ュ憡](https://www.imooc.com/article/23004)
以上是关于娴呭嚭GEOHASH绠楁硶的主要内容,如果未能解决你的问题,请参考以下文章
[娣卞叆娴呭嚭LB]鎵嬫妸鎵嬪甫浣犲疄鐜颁竴涓礋杞藉潎琛″櫒
娣卞叆娴呭嚭璁$畻鏈虹粍鎴愬師鐞嗭細鏁版嵁瀹屾暣鎬э紙涓嬶級-濡備綍杩樺師鐘姜鐜板満锛堢50璁诧級
銆愬崄澶╄嚜鍒惰蒋娓叉煋鍣ㄣ€慏AY 02锛氱敾涓€鏉$洿绾匡紙DDA 绠楁硶 & Bresenham鈥檚 绠楁硶锛?/a>