吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1048|回复: 7
收起左侧

[其他原创] 使用VB实现geohash算法

[复制链接]
daolao123 发表于 2023-5-11 19:40
GeoHash用一个字符串表示一个经纬度坐标,将一个二维向量转化为一个一维向量。GeoHash可以方便位置的索引。
使用VB实现经纬度的geohash编码,给出一个VB函数。
[Visual Basic] 纯文本查看 复制代码
Public Function encodeGeoHash(Latitude, Longitude, Precision)
Dim BITS() As Variant
Dim BASE32() As Variant
BITS = Array(16, 8, 4, 2, 1)
BASE32 = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", _
                "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", _
                "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", _
                "y", "z")
Dim isEven As Boolean
isEven = True
i = 0
Bit = 0
ch = 0
Geohash = ""
Dim latMin As Double, latMax As Double
Dim lonMin As Double, lonMax As Double
latMin = -90#
latMax = 90#
lonMin = -180#
lonMax = 180#
Dim tempMid As Double
While (Len(Geohash) < Precision)
    If isEven Then
        tempMid = (lonMin + lonMax) / 2
        If Longitude > tempMid Then
            ch = ch Or BITS(i)
            lonMin = tempMid
        Else
            lonMax = tempMid
        End If
    Else
        tempMid = (latMin + latMax) / 2
        If Latitude > tempMid Then
            ch = ch Or BITS(i)
            latMin = tempMid
        Else
            latMax = tempMid
        End If
    End If
    isEven = Not isEven
    If i < 4 Then
        i = i + 1
    Else
        Geohash = Geohash & BASE32(ch)
        i = 0
        ch = 0
    End If
Wend
encodeGeoHash = Geohash
End Function

免费评分

参与人数 2吾爱币 +7 热心值 +2 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
rnadow + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

约定的童话 发表于 2023-5-12 07:38
以下是使用Python实现GeoHash算法的代码:

```python
import math

def geohash(lat, lng, length):
    lat_interval = 90.0 / length
    lng_interval = 180.0 / length
    lat_buckets = int(math.ceil(180.0 / lat_interval))
    lng_buckets = int(math.ceil(360.0 / lng_interval))
   
    lat_bin = 0
    lng_bin = 0
    hash_value = ""
   
    for i in range(length):
        if i < lat_buckets:
            lat_delta = lat_interval * i
            lat_bin += int(math.floor(lat + lat_delta))
        else:
            lat_bin += int(math.floor(lat + (180.0 if i >= lat_buckets - 1 else lat_interval)))
        
        if i < lng_buckets:
            lng_delta = lng_interval * i
            lng_bin += int(math.floor(lng + lng_delta))
        else:
            lng_bin += int(math.floor(lng + (360.0 if i >= lng_buckets - 1 else lng_interval)))
        
        hash_value += str(lat_bin << 1) + str(lng_bin)
   
    return hash_value
```

该函数接受三个参数:`lat`表示纬度,`lng`表示经度,`length`表示生成的哈希值长度。例如,如果要生成2位GeoHash编码,则将`length`设置为2。函数将返回一个字符串,表示生成的GeoHash编码。
vethenc 发表于 2023-5-11 23:08
度娘灬魂手 发表于 2023-5-11 23:17
CXC303 发表于 2023-5-12 07:04
很新鲜的思路,支持
qqqwh 发表于 2023-5-12 10:35
学习了,谢谢分享
曾经的歌42 发表于 2023-5-12 14:13
在学校学VB前都没听说过VB
zxsbk 发表于 2023-5-18 16:04
VB图像界面好用。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-14 11:30

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表