Geohash algorithm and point-golang for the nearest region

Source: Internet
Author: User
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))}}  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.