This is a creation in Article, where the information may have evolved or changed.
The Geohash algorithm and the point of the nearest region are used to encapsulate these two algorithms into the Golang package, which is useful when writing the LBS service.
Https://github.com/gansidui/geohash
Https://github.com/gansidui/nearest
Gohash
package mainimport ( "fmt" "github.com/gansidui/geohash")func main() { latitude := 39.92324 longitude := 116.3906 precision := 5 hash, box := geohash.Encode(latitude, longitude, precision) fmt.Println(hash) fmt.Println(box.MinLat, box.MaxLat, box.MinLng, box.MaxLng) neighbors := geohash.GetNeighbors(latitude, longitude, precision) for _, hash = range neighbors { fmt.Print(hash, " ") }}
Nearest
Package Mainimport ("FMT" "Github.com/gansidui/nearest") func main () {near: = nearest. Newnearest () near. Setprecision (5) near. Addcoord ("A", 40.92424, 116.3906) near. Addcoord ("B", 39.93224, 116.3927) near. Addcoord ("C", 39.92484, 116.3916) near. Addcoord ("D", 39.92494, 116.3923) near. Addcoord ("E", 39.92220, 116.3915) near. Addcoord ("F", 39.92424, 117.3906) keys: = near. Querynearestsquarefromkey ("C") coordNode1, OK: = near. Getcoordnode ("C") if!ok {return} for _, Key: = Range Keys {CoordNode2, _: = near. Getcoordnode (Key) fmt. Println (key, nearest. Distancecoordnode (CoordNode1, CoordNode2))}}